#include <iostream>
using namespace std;
struct node{
int value;
node* next;
};
node * createList(int N);
void display(node* head);
int main()
{
int N;
cout<<"请输入结点个数:";
cin>>N;
node * head = createList(N);
display(head);
return 0;
}
node* createList(int N)
{
node * head = new node();
node * cur = head;
for (int i = 0;i<N;i++)
{
cur->value=rand()%10;
cur->next = new node();
cur= cur->next;
}
return head;
}
void display(node *head)
{
node * cur = head;
while (cur)
{
cout<<cur->value<<" ";
cur = cur->next;
}
cout<<endl;
}
创建单链表
最新推荐文章于 2022-10-21 23:21:58 发布