#include <iostream>
using namespace std;
static int x=0;
class node {
private:
int data;
node *next;
node *head;
node *p;//固定投
node *f;//判斷是否跑最後一個
public:
void in(int t)
{
if(x==0)
{
node *n=new node;
head=n;
n->next=p;
n->data=t;
f=head;
x=x+1;
}
else{
while(f->next!=NULL)
{f=f->next;}
f->next=new node;
f=f->next;
f->data=t;
f->next=p;
}
}
void print()
{
node *f=head;
while(f!=NULL)
{
cout<<f->data<<"---";
f=f->next;
}
cout<<"\n";
}
node ()
{p=NULL;}
};
int main()
{
node a;
for(;;)
{
cout<<"---------------\n"
<<"1.輸入\n"
<<"2.列印全部\n"
<<"3.EXIT\n"
<<"---------------\n";
int section;
cin>>section;
if(section==1)
{
cout<<"輸入數字\n";
int i;
cin>>i;
a.in(i);
}
if(section==2)
{a.print();}
if(section==3)
{cout<<"安心上路\n";
break;}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.240.186.16