//以下是一个有关于链表操作的问题(包括几种其本的操作)
//其中有一个是游离态的函数(MENU)
//纯C++的DOS界面的不如VC++可视化的界面好看,但是重要的是思想
#include <iostream.h>
struct base
{
struct base* next;
int fdate;
};
class clist
{
public:
struct base* phead;
clist(struct base* head=NULL);
clist();
struct base* search(int nsearch);
struct base* del(int nsearch);
struct base* insert(int ninsert,int nsearch);
};
clist::clist(struct base* head=NULL)
{
phead=head;
}
clist::~clist()
{
}
struct base* clist::search(int nsearch)
{
struct base* pcurrent=new [sizeof(struct base)];;
struct base* pold=new [sizeof(struct base)];
pold->next=NULL;
pcurrent=phead;
pold=phead;
while(pcurrent->next!=NULL)
{
if (pcurrent->ndate==nsearch)
{
break;
}
pold=pcurrent;
pcurrent=pcurrent->next;
}
return pold;
}
struct base* clist::del(int ndel)
{
struct base* pold=new [sizeof(struct base)];
struct base* pdel=new [sizeof(struct base)];
pold->next=NULL;
pold=search(ndel);
pdel=pold->next;
pold->next=pdel->next;
delete pdel;
return pold;
}
void clist::insert(int ninsert,int nsearch);
{
struct base* pold;
struct base* pcurrent=new [sizeof(struct base)];
pcurrent->next=NULL;
pold=search(nsearch);
pcurrent->next=pold->next;
pold->next=pcurrent;
return pcurrent;
}
void clist::create()
{
struct base* pcurrent;
struct base* pold;
pcurrent=phead;
do
{
pcurrent=new [sizeof(struct base)];
cout<<"please input your date:"<<endl;
cin>>pcurrent->ndate;
pold->next=pcurrent;
pold=pcurrent;
}while(ndate!=0);
pcurrent->next=NULL;
}
int menu()
{
int num
cout<<"============================================="<<endl;
cout<<"=== 0.search a date ==="<<endl;
cout<<"=== 1.del a date ==="<<endl;
cout<<"=== 2.insert a date ==="<<endl;
cout<<"=== 3.exit the program ==="<<endl;
cout<<"============================================="<<endl;
cout<<"::please input your choice:";
cin>>num;
return num;
}
int main()
{
struct base* head=new [sizeof(struct base)];
int choice;
clist table(head);
table.table();
do
{
choice=menu();
if (choice=-9999)
break;
switch(choice)
{
case 0:
cout<<"please input the date:"<<endl;
cin>>ndate;
if(!table.search(ndate))
cout<<"none!"<<endl;
else
cout<<"success!"<<endl;
break;
case 1:
cout<<"please input the date:"<<endl;
cout>>ndate;
if(table.del(ndate))
cout<<"success!"<<endl;
else
cout<<"failed"<<endl;
break;
case 2:
cout<<"please input dates"<<endl;
cout>>ndate1>>ndate2;
if(!table.insert(ndate1,ndate2))
cout<<"failed!"<<endl;
else
cout<<"success!"<<endl;
break;
default:
cout<<"error!"<<endl;
}
}while(1);