#include <iostream>
#include<stdlib.h>
using namespace std;
struct node
{
int x;
struct node *next;
};
//顺序建表
struct node *creatListShun(int lenth)
{
struct node *head,*t,*p;
int i;
head=(struct node *)malloc(sizeof(struct node));
head->next=NULL;
t=head;
for(i=0; i<lenth; i++)
{
p=(struct node *)malloc(sizeof(struct node));
p->x=i;
p->next=NULL;
t->next=p;
t=p;
}
return head;
}
int main()
{
struct node *head1,*t1;
head1=creatListShun(10);//顺序建链表
t1=head1->next;
cout<<"顺序建链表 :";
while(t1!=NULL)
{
cout<<t1->x<<" ";
t1=t1->next;
}
cout<<endl;
return 0;
}
顺序建链表
最新推荐文章于 2023-06-13 16:56:01 发布