#include<string.h>
#include<iostream.h>
#include<stdio.h>
#include<stdlib.h>
//鏈表結構
struct wq
{
?wq(){x=9999;}
? int x;
? //char name[10]; //復雜結構的遍歷
? wq* link;
};
int num=0;//鏈表的個數
//bool real[100];//是否有長串

//菜單函數
void Tool();
//創建堆棧結構
void creatlink(wq*head);
//遍歷鏈表
void getout(wq* head);
//插入元素
void insertI(wq* head );
//刪除元素
void dxy(wq* head );
//釋放堆棧
void deleall(wq* head);
//查找函數
void findme(wq* me);
void main()
{
?bool re = true; int? can=0;
?wq * me=new wq;
?me->link=NULL;
?while (re)
?{
?? int w;
??Tool();
??cout<<"give me a number!"<<endl;
??cin>>w;
??switch (w)
??{
??case 1:
???if(can==1)
???{
????char m;
????cout<<"you will destroy the frist one!?? y/n"<<endl;
????cin>>m;
????if(m=='y'||m=='Y')
????{
?????can = 0;
?????deleall(me);
????}
???}
???creatlink(me);can=1;
???break;
??case 2:
???getout(me);
???break;
??case 3:
???dxy(me);
???break;
??case 4:
???insertI(me);
???break;
??case 5:
???findme(me);
???break;
??case 6:
???deleall(me);
???break;
??case 7:
???re = false;
???break;
??}
?}

}
//創建堆棧wq *n1=new wq;
void creatlink(wq*head)
{????????
? bool yen=1;
? while(yen)
? {??//char m;
?? int s;
?? //real[num]=false;
??head->link=new wq;
??cout<<"請輸入堆棧的數據"<<endl;
??cin>>head->link->x;
??//cout<<"是否輸入字符長串?y/n? ";
??//cin>>m;????? cout<<"?? ";
??? //if(m=='Y'||m=='y')
? //? {
?// real[num]=1;flushall();
?// gets(head->link->name );
?// cout<<" end ";
?//?? }
? head =head->link ;
? head->link = NULL;
? num++;
? cout<<"是否繼續?1=繼續,0=退出!?? ";
? cin>>s;
? if(s==0)? yen=0;
?}
}
//遍歷鏈表
void getout(wq* head)
{
?wq* temp;
?if(num==0)
?{
? cout<<"no"<<endl;
?}else
?{
? for(int i= 0;i<10;i++)
? cout<<"-";
? cout<<endl;
? while(head)
?? {
?? int i=0;
?? temp=head;
??? head=head->link;
? cout<<"堆棧的元素是:"<<endl;
? cout<<temp->x<<endl;
? //if(real[i])
?// {//??????
//???? for(int i= 0;i<10;i++)
?//? cout<<temp->name[i];
?// }
? cout<<endl;i++;
?? }
}
}
//插入元素
void insertI(wq* head)
{
?int w=0,wo=0;
?cout<<"輸入要插入的位置!"<<endl;
?cin>>w;
?cout<<"插入的值?"<<endl;
?cin>>wo;
?? if(w>num) {cout<<"the all is:"<<num<<endl<<"越界"<<endl;return;}
?? int op=0;
??? while(head)
??? {??
??head=head->link;
??op++;
??if(op==w-1)
??{
???wq * me;
???me = head->link;
???head->link = new wq;
???head->link->x=wo;
? /*cout<<"輸入長串? y/n"<<endl;*/
???head->link->link=me;
??}
?}
?
}
//刪除元素
void dxy(wq* head)
{
?int ip=0,w=0;
?cout<<"輸入要刪除第幾個元素?"<<endl;
?cin>>w;
?? if(w>num)
??? {
? cout<<"鏈表元數的個數"<<num<<endl;
? return;
???? }
?while(head)
?{
? if(ip==w-1) {
?? wq * me;me=head->link;
?? head->link =head->link->link;
? free(me ); num--;return;}? head=head->link;ip++;
?}
}
//釋放堆棧
void deleall(wq* head)
{
?wq* tem;num=0;
? while(head)
{
?? tem=head;
?head=head->link;
?free(tem);
}
?cout<<"釋放完畢!"<<endl;
}
// 菜單函數
void Tool()
{
?cout<<"*****************************"<<endl;
?cout<<"???????? 1.creat"<<endl;
?cout<<"???????? 2.cout"<<endl;
?cout<<"???????? 3.delete"<<endl;
?cout<<"???????? 4.insert"<<endl;
?cout<<"???????? 5.find"<<endl;
?cout<<"???????? 6.free"<<endl;
?cout<<"???????? 7.out"<<endl;
?cout<<"****************************"<<endl;

}
//查找函數
void findme(wq* me)
{
?int who;
?cout<<"輸入要查找的元素?"<<endl;
?cin>>who;
?while(me)
??{
???me=me->link;
???if(me->x==who)
???{
????cout<<"find!"<<endl;return;
???}
???
??}
}
/*
void put(int q,char p)
{
?while(q)
?{
? cout<<p;q--;
?}
}
void Tool()
{
?// 第一行
?put(3,' ');put(17,'=');cout<<endl;
?// 第二行
?put(3,' ');put(2,'|');put(4,' ');cout<<"1.creat";put(2,' ');put(2,'|');cout<<endl;
?put(3,' ');put(2,'|');put(4,' ');cout<<"2.cout";put(3,' ');put(2,'|');cout<<endl;
?put(3,' ');put(2,'|');put(4,' ');cout<<"3.delete";put(1,' ');put(2,'|');cout<<endl;
?put(3,' ');put(2,'|');put(4,' ');cout<<"4.insert";put(1,' ');put(2,'|');cout<<endl;
?put(3,' ');put(2,'|');put(4,' ');cout<<"5.free";put(3,' ');put(2,'|');cout<<endl;
?put(3,' ');put(2,'|');put(4,' ');cout<<"6.out";put(4,' ');put(2,'|');cout<<endl;
?put(3,' ');put(17,'=');cout<<endl;
}
// 接受輸入
void dothings(wq* ty)
{
?bool rel=1; char yi,kl;int e,w;
?cout<<"put a char tell me ";cin>>yi;
?while(rel){
? switch (yi)
? {
?? case '1': creatlink(ty);cout<<"end!"<<endl;dothings(ty);break;
?? case '2': getout(ty);cout<<"end!"<<endl;dothings(ty);break;
?? case '3':cout<<"輸入刪除的索引號!";cin>>e;dxy(ty,e);dothings(ty);break;
?? case'4':? cout<<"輸入插入的索引號!";cin>>w;cout<<"輸入插入的索引號的值!";
??? cin>>kl;inserI(ty,w,kl);dothings(ty);break;
?? case'5': deleall(ty);dothings(ty);break;
?? case'6':rel=0;break;
?? default:Tool();dothings(ty);break;

?}
?}
}*/
/* 沒有反轉鏈表的函數*/
/* 沒有查找函數*/
//遍歷鏈表

?