| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 434 人关注过本帖
标题:链表的操作
只看楼主 加入收藏
coding
Rank: 1
等 级:新手上路
威 望:1
帖 子:60
专家分:0
注 册:2007-9-30
收藏
 问题点数:0 回复次数:2 
链表的操作


//以下是一个有关于链表操作的问题(包括几种其本的操作)
//其中有一个是游离态的函数(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);


搜索更多相关主题的帖子: 链表 
2007-10-13 16:56
aipb2007
Rank: 8Rank: 8
来 自:CQU
等 级:贵宾
威 望:40
帖 子:2879
专家分:7
注 册:2007-3-18
收藏
得分:0 
what's the problem or just sharing.

Fight  to win  or  die...
2007-10-13 19:20
coding
Rank: 1
等 级:新手上路
威 望:1
帖 子:60
专家分:0
注 册:2007-9-30
收藏
得分:0 

today,my classmate asks me something about the how to create it ,delete it ,and insert a element in the table,the process meets for the answer.but i think in the vc++,these problem can be do easy with the CStirng and MultiArrary .


2007-10-13 19:26
快速回复:链表的操作
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.019866 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved