- 黑桃云
-
#include <iostream.h>
#include <QUEUE>
using namespace std;
struct Node
{
int data;
struct Node *link;
};
void appendx(Node *b,int c){
Node *h=NULL;
h=b;
Node a={c,0};
if(h->link==NULL){
h->link=&a;
cout<<"chuci"<<endl;
return;
}
while(h->link!=NULL)
h=h->link;
h->link=&a;
cout<<"houci"<<endl;
return;
}
void outputx(Node *b){
Node *h=NULL;
h=b;
while(h!=NULL){
cout<<h->data<<endl;
h=h->link;
}
return;
}
int main(){
Node c={0,0};
int flag,element;
while(true){
cout<<"是否向链表添加元素? <0>停止 <1>继续"<<endl;
cin>>flag;
if(!flag)
break;
cin>>element;
appendx(&c,element);
}
cout<<"输出链表内容。"<<endl;
outputx(&c);
return 0;
}