#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++ 链表,最简单的创建
最新推荐文章于 2025-12-29 22:37:36 发布
本文介绍了一个简单的C++程序,用于创建一个单向链表,并实现链表元素的输入与输出。通过循环和指针操作,展示了链表的基本操作方法。
4801

被折叠的 条评论
为什么被折叠?



