<span style="font-size:18px;">#include<iostream>
using namespace std;
struct node
{
int data;
struct node* next;
};
struct node*creat()
{
node*head,*p,*q;
int i=0;
head=(node*)malloc(sizeof(node));
while(1)
{
int x;
cout<<"请输入链表的数据"<<endl;
cin>>x;
if(x==0)
break;
p=(node*)malloc(sizeof(node));
p->data=x;
if((++i)==1)
{
head->next=p;
}
else
{
q->next=p;
}
q=p;
}
q->next=head;
return head;
}
int main()
{
//创建链表
node *creat();
return 0;
}
</span>
单循环链表
最新推荐文章于 2021-09-23 21:56:19 发布