下面个人缩写,如有代码繁琐或错误请勿喷,如果可以的话,请指出,谢谢
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
typedef int ElemType;
typedef struct LNode
{
ElemType data;
struct LNode* next;
}LNode, *LinkList;
LinkList Tail_Insert(LinkList head, LinkList r)
{
for (int i = 0; i < 10; ++i)
{
LinkList s = (LinkList)malloc(sizeof(LNode));
if (s == nullptr) exit(1);
if (r == nullptr)
{
s->data = i;
s->next = nullptr;
head = s;
r = s;
}
else
{
s->data = i;
s->next = r->next;
r->next = s;
r = s;
}
}
r = nullptr;
return head;
}
LinkList Head_Insert(LinkList head)
{
for (int i = 0; i < 10; ++i)
{
LinkList s = (LinkList)malloc(sizeof(LNode));
if (s == nullptr) return nullptr;
s->data = i;
s->next = head;
head = s;
}
return head;
}
LinkList Init_List()
{
LinkList head = nullptr;
LinkList r = head;
head = Tail_Insert(head, r);
//head = Head_Insert(head);
return head;
}
void Print_List(LinkList head)
{
while (head != nullptr)
{
printf("%4d", head->data);
head = head->next;
}
}
int main()
{
LinkList head = nullptr;
head=Init_List();
Print_List(head);
return 0;
}