📄 ulist.cpp
字号:
//#include <iostream>
//#include <fstream>
//using namespace std;
//#include "Ulist.h"
//
//void CUlist::posfun(int a)//五种排序方式的通用函数 内含switch语句
// {
// int b;//临时变量,用来记录下面五种排序方式
// for (int j=0;j<=GetCount();j++)
// {p1=head; p2=p1->Next;
// for (int i=0;i<GetCount()-1-j;i++)
// {
// switch (a)
// { case 1:{b=strcmp(p1->Name,p2->Name);break;}//b的值为-1,0,1
// case 2:{b=strcmp(p1->Number,p2->Number);break;}
// case 3:{b=p1->Score[0]>p2->Score[0]?1:0;break;}
// case 4:{b=p1->Score[1]>p2->Score[1]?1:0;break;}
// case 5:{b=p1->Score[2]>p2->Score[2]?1:0;break;} }
// if ((-1==b-int(m_dec))||(0==b-int(m_dec)))//dec取值0或者1,b取值-1,0,1;若升序则差值为-1,降序则差值为0;
// { if (p1==head)//head指针
// { temp=p2->Next;
// p2->Next=p1;
// p1->Next=temp;
// head=p2;
// p2=p1->Next;
// last=p2;
// p=head;}
// else //后头的指针
// { temp=p2->Next;
// p->Next=p2;
// p2->Next=p1;
// p1->Next=temp;
// p2=p1->Next;
// last=p2;
// p=p->Next;
// }
// }
// else //不满足 直接后移指针
// { if (p1!=head)
// p=p->Next;
// p1=p1->Next;
// p2=p2->Next;
// last=p2;
// }
// }p=head;
// }
//}
//CUlist::CUlist(void)//构造函数
//{
// m_Count=0;
// head=NULL;//链表头指针
// p1=NULL;//链表排序和删除时的辅助指针
// p2=NULL;//链表排序时的辅助指针
// temp=NULL;//链表排序时的辅助指针
// p=NULL;//链表排序时的辅助指针
// last=NULL;//链表排序时的辅助指针
//}
//CUlist::~CUlist(void)//析构函数
//{}
//CUlist::CUlist(const CUlist & aList)//拷贝构造函数// =、 + 、== 运算符的重载----需实现
//{
// m_Count=0;
// head=new STUDENT; p1=head; STUDENT *P_TEMP=aList.head;//开头先定位好指针
// for (int n=0;n<aList.m_Count;n++)//不断赋值过程
// {
// strcpy(p1->Name,P_TEMP->Name);
// strcpy(p1->Number,P_TEMP->Number);
// p1->Score[0]=P_TEMP->Score[0];
// p1->Score[1]=P_TEMP->Score[1];
// p1->Score[2]=P_TEMP->Score[2];
// p1->ScoreCount=P_TEMP->ScoreCount;
// P_TEMP=P_TEMP->Next;
// m_Count++;
// p1->Next=new STUDENT;p1=p1->Next;
// }
//}
//CUlist CUlist::operator +(CUlist &B)//加号重载
//{
// m_Count+=B.m_Count;
// B.temp=B.head;
// for(int i=0;i<(B.GetCount()-3);i++)
// last=last->Next;//开头先定位好指针
// for (int n=0;n<B.GetCount();n++)
// {
// last->Next=new STUDENT;
// last=last->Next;
// strcpy(last->Name,B.temp->Name);
// strcpy(last->Number,B.temp->Number);
// last->Score[0]=B.temp->Score[0];
// last->Score[1]=B.temp->Score[1];
// last->Score[2]=B.temp->Score[2];
// last->ScoreCount=B.temp->ScoreCount;
// B.temp=B.temp->Next;
// }
// return *this;
//}
//CUlist CUlist::operator =(CUlist &B)//等号重载
//{
// head=new STUDENT;last=head;
// B.temp=B.head;//开头先定位好指针
// for (int n=0;n<B.GetCount();n++)
// {
// strcpy(last->Name,B.temp->Name);
// strcpy(last->Number,B.temp->Number);
// last->Score[0]=B.temp->Score[0];
// last->Score[1]=B.temp->Score[1];
// last->Score[2]=B.temp->Score[2];
// last->ScoreCount=B.temp->ScoreCount;
// last->Next=new STUDENT;
// last=last->Next;B.temp=B.temp->Next;
// }
// return *this;
//}
//bool CUlist::operator ==(CUlist &B)//==号重载
//{
// temp=head;
// B.temp=B.head;//开头先定位好指针
// for (int n=0;n<GetCount();n++)
// {
// if(strcmp(B.temp->Name,temp->Name))return false;
// if(strcmp(B.temp->Number,temp->Number))return false;
// if(B.temp->Score[0]!=temp->Score[0])return false;
// if(B.temp->Score[1]!=temp->Score[1])return false;
// if(B.temp->Score[2]!=temp->Score[2])return false;
// if(B.temp->ScoreCount!=temp->ScoreCount)return false;
// B.temp=B.temp->Next;temp=temp->Next;
// } return true;
//}
//bool CUlist::Add(/*STUDENT & aStudent*/)//增加一条学生记录---要保证原有的排列顺序
//{
// ifstream datafile;
// datafile.open("d:\\student.txt");
// if(!datafile){cerr<<"wrong!"<<endl;exit(1);}
// while(!datafile.eof())
// {
// if (!GetCount())
// {
// head=new STUDENT;
// datafile>>head->Name>>head->Number>>head->Score[0]>>head->Score[1]>>head->Score[2]>>head->ScoreCount;m_Count++;
// last=head;
// }
// if (GetCount())
// {
// last->Next=new STUDENT;
// last=last->Next;
// datafile>>last->Name>>last->Number>>last->Score[0]>>last->Score[1]>>last->Score[2]>>last->ScoreCount;m_Count++;
// }
//
//}
// return Sort(m_Posorder,m_dec);//再按照原有的排序方式再排一次序.
//
//}
//void CUlist::Clear()//清空所有记录
//{
// p1=head;
// STUDENT * del;
// for(int i=0;i<GetCount();i++)
// {
// del=p1;
// p1=p1->Next;
// delete del;
// }
// m_Count=0;
// cout<<"已经清空"<<endl;
//}
//bool CUlist::Delete(char *Number)//根据学号从链表中删除某条记录
//{
// if(atof(head->Number)==atof(Number))//转换成数据,更为简便.
// {
// p1=head->Next;
// delete head;
// m_Count--;
// head=p1;
// }
// else
// {
// p1=head->Next;
// STUDENT *del=head;
// cout<<GetCount();
// for(int i=0;i<GetCount()-1;i++)
// {
// if (atof(p1->Number)==atof(Number))//同上
// {
// del->Next=p1->Next;
// delete p1;
// p1=del->Next;
// m_Count--;
// break;
// }
// else {p1=p1->Next;del=del->Next;}
// }
// }
// return true;
//}
//STUDENT CUlist::Find(char *Name)//根据名称寻找某个学生
//{
// temp=head;
// int n_length=strlen(Name);int nCount;
// for(int i=0;i<GetCount();i++)
// {
// for (nCount=0;nCount < n_length;nCount++)
// {
// if (Name[nCount]!=temp->Name[nCount])
// break;
// }
// if (nCount==n_length)//如果break执行完后ncount只比strlen小一,说明每个字符都是一样的,则满足条件.
// {
// cout<<"他的学号是: "<<temp->Number<<endl;
// return *temp;
// }
// else temp=temp->Next;
// }
//}
//int CUlist::GetCount()//获得记录数
//{
// return m_Count;
//}
//bool CUlist::OutPutFile(char *pFileName)//将数据输出到一个文本文件中
//{
// fstream out;
// out.open(pFileName,ios::out);
// p1=head;
// for(int n=0;n<GetCount();n++)
// {
// out<<"学生"<<n+1<<": "<<p1->Number<<'\t'<<p1->Name<<'\t';
// for (int i=0;i<3;i++)
// out<<p1->Score[i]<<'\t';
// out<<endl;
// p1=p1->Next;
// }
// out.close();
// return true;
//}
//bool CUlist::Sort(int pos, bool dec)// pos为1-5,分别表示按名称、学号、成绩1、成绩2、成绩3排序;m_dec 表示升序还是降序
//{
// this->m_Posorder=pos;//将排序方式赋值给成员变量,以便记录.
// this->m_dec=dec;
// p=head;
// p1=head;
// if (GetCount()>=2)
// {
// if (1==pos){posfun(pos);}//以下五个函数都是五种排序方式的通用函数,实现部分请看本文件开头.
// else if (2==pos){posfun(pos);}
// else if (3==pos){posfun(pos);}
// else if (4==pos){posfun(pos);}
// else if (5==pos){posfun(pos);}
// }
// return true;
//}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -