尾插法建立建表
typedef struct node {int value;struct node* next;
}node, * Linklist;
void creatlist(Linklist &l)
{Linklist tp;Linklist lst;l = NULL;l = (Linklist)malloc(sizeof(node));lst = l;int a;while (cin >> a && a > 0){tp = (Linklist)malloc(sizeof(node));tp->value = a;lst->next = tp;lst = tp;}lst->next = NULL;
}
头插法建立链表
typedef struct node {int value;struct node* next;
}node, * List;
void creatlist(List& L)
{List p;int tp;L = (List)malloc(sizeof(node));L->next = NULL;while (cin >> tp && tp >= 0){p = (node *)malloc(sizeof(node));p->value = tp;p->next = L->next;L->next = p;len++;}
}
相关题目