#include<iostream>
#include<stdlib.h>
using namespace std;
typedef struct L{
int data;
struct L *next;
};
int main(){
int i,n;
L *p,*head,*q;
head=NULL;
cout<<"how many list be created?\n";
cin>>n;
head=p=(L*)malloc(sizeof(L));
cin>>head->data;
for(i=1;i<n;i++){
q=(L*)malloc(sizeof(L));
cin>>q->data;
q->next=NULL;
p->next=q;
p=q;
}
p=head;
cout<<"output them:\n";
while(p!=NULL){
cout<<p->data<<endl;
p=p->next;
}
return 0;
}
日记——C/C++ 链表,最简单的创建
最新推荐文章于 2024-09-16 16:07:55 发布