可供参考:
https://blog.csdn.net/qq_41028985/article/details/82859199
头插入是指在链表的表头节点之后(记得是表头),之前插入的部分被顶到了后面
void CreateListHead(LinkList *L, int n)
{
LinkList p;
int i;
srand(time(0));
*L = (LinkList)malloc(sizeof(Node));
(*L)->next = NULL;
for(i=0; i < n; i++)
{
p->data = rand()%100+1;
p->next = (*L)->next;//****先把表头next链接到新建立节点的next****
(*L)->next = p;//****把表头的next指针指向新建立节点
}
}
尾插法就是常用的插入方法,比较容易理解。
void CreateListtail(Listlist *head,int n)
{
int *p,*end;
Linklist node;
srand(time(0));
head = (Linklist)malloc(sizeof(Node));
(*head)->next = NULL;
for(int i = 0; i <=n-1;i++ )
{
node = (Linklist)malloc(sizeof(Node));
node->data = rand()%100+1;
end->next = node;
end = node
}