Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2348919
  • 博文数量: 816
  • 博客积分: 10000
  • 博客等级: 上将
  • 技术积分: 5010
  • 用 户 组: 普通用户
  • 注册时间: 2008-12-17 17:57
文章分类

全部博文(816)

文章存档

2011年(1)

2008年(815)

分类:

2008-12-17 18:08:55


#include
#include
#include
#include
void filelist()
{
fstream flist;
char ch;
cout<<"文件列表:"<flist.open("filelist.txt",ios::in);
while(flist.get(ch))
cout<flist.close();
}
//-----------------------------------------------------------------------------------------
void inti()
{
cout<<"-------------------------------------------------------------------------------"<    cout<<"1 添加"<<"\t"<<"2 删除"<<"\t"<<"3 排序"<<"\t"<<"4 查找"<<"\t"<<"5 修改"<cout<<"6 显示"<<"\t"<<"7 清屏"<<"\t"<<"8 存档"<<"\t"<<"9 读档"<<"\t"<<"10 打印"<<"\t"<<
"11 查看文件"<cout<<"-------------------------------------------------------------------------------"<}
//--------------------------------------------------------------------------------------
template                      //规范输入函数
void cin_judge(istream & cin,type& i)
{
while(!cin)
{
cin.clear();
cin.ignore(100,'\n');
cout<<"请重输入"<cin>>i;
}
}
class item
{
public:

char name[80];
int score;
item *prior;
item *next;
};
//----------------------------------------------------------------------------------------
template
class list
{
public:
list();
void add();
int remove();
void paixu();
item *find();
int change();
void show();
    int save();
    int read();
    void fileprint();
private:
type *head,*end;
};
//-----------------------------------------------------------------------------------------
template
list::list()
{
end=head=0;
}
//------------------------------------------------------------------------------------------
template
void list::add()
{
item *p;
    p=new type;
if(!p)
{
cout<<"allocation error.\n";
exit(1);
}
cout<<"名字:"<cin>>p->name;
cout<<"成绩:"<cin>>p->score;
cin_judge(cin,p->score);
if(head==0)
{
head=end=p;
p->prior=p->next=NULL;
}
else
{
p->prior=end;
end->next=p;
end=p;
end->next=0;
}
}
//------------------------------------------------------------------------------------------
template
int list::remove()
{
type*p=find();
if(p==0) return 0;
if(p->prior)
{
if(p->next)
{
p->next->prior=p->prior;
p->prior->next=p->next;
}
else
{
p->prior->next=0;
end=p->prior;
}
}
else
{
if(p->next)
{
p->next->prior=0;
head=p->next;
}
else
{
head=end=0;
}
}
    delete p;
return 0;
}
//-----------------------------------------------------------------------------------
template
void list::paixu()
{
int j=0,temp;
char temp1[80];
type *p=head;
for(;p!=0;p=p->next) j++;
p=head;
for(int i=0;i{
if(j!=1)
{
if(p->scorenext->score)
{
temp=p->score;
strcpy(temp1,p->name);
p->score=p->next->score;
strcpy(p->name,p->next->name);
            p->next->score=temp;
strcpy(p->next->name,temp1);
}
p=p->next;
if(p->next==0) p=head;
}
}
}
//------------------------------------------------------------------------------------
template
item *list::find()
{
    char fname[80];
type *p=head;
cout<<"输入名字:";
cin>>fname;
for(;p;p=p->next)
    if(!strcmp(p->name,fname))
{
cout<name<<"  "<score<return p;
}

cout<<"不存在!"<return 0;
}
//-------------------------------------------------------------------------------------
template
int list::change()
{
type *p=find();
if(p==0) return 0;
cout<name<<"的成绩改为:";
cin>>p->score;
cin_judge(cin,p->score);
return 0;
}
//-------------------------------------------------------------------------------------
template
void list::show()
{
item *p;
for(p=head;p!=0;p=p->next)
cout<name<<"   "<score<}

//----------------------------------------------



--------------------next---------------------

阅读(1603) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~