#include <iostream>
using namespace std;
static int x=0;
class node {
private:
int data;
node *next;
node *head;
public:
void in(int t)
{
node *f=new node;
f->next=head;//把next指的東西根head指的東西設成一樣 都指向下一個
f->data=t;
head=f;//把f變成第一個
}
int out()
{
node *f=head;
head=head->next;
int b=f->data;
delete f;
return b;
}
void MAXmin()
{
node *x=head;
node *y;
node *a=new node;
for(;;x=x->next)
{ if(x!=NULL)
{for(y=x->next;;y=y->next)
{if(y!=NULL)
{if(x->data<y->data)
{a->data=x->data;
x->data=y->data;
y->data=a->data;}
}
else break;
}}
else break;
}
print();
}
void minMAX()
{
node *x=head;
node *y;
node *a=new node;
for(;;x=x->next)
{ if(x!=NULL)
{for(y=x->next;;y=y->next)
{if(y!=NULL)
{if(x->data>y->data)
{a->data=x->data;
x->data=y->data;
y->data=a->data;}
}
else break;
}}
else break;
}
print();
}
void print()
{
node *f=head;
while(f!=NULL)
{
cout<<f->data<<"---";
f=f->next;
}
cout<<"\n";
}
node ()
{head=NULL;}
};
int main()
{
node a;
for(;;)
{
cout<<"---------------\n"
<<"1.輸入\n"
<<"2.刪除\n"
<<"3.列印全部\n"
<<"4.從大至小排\n"
<<"5.從小至大排\n"
<<"6.EXIT\n"
<<"---------------\n";
int section;
cin>>section;
if(section==1)
{cout<<"輸入數字\n";
int i;
cin>>i;
a.in(i);}
if(section==2)
{cout<<a.out();}
if(section==3)
{a.print();}
if(section==4)
{a.MAXmin();}
if(section==5)
{a.minMAX();}
if(section==6)
{cout<<"安心上路\n";
break;}
}
}
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.240.186.16