?? liststudent.cpp
字號:
#include <iostream>
#include "liststudent.h"
Linkstudent * Liststudent :: get_first()
{
return first;
}
bool Liststudent::insert(const Student & stu)
{
first->next = new Linkstudent(stu, first->next);
if(tail == first)
tail = first->next;
size++;
return true;
}
bool Liststudent::append(const Student &stu)
{
tail->next = new Linkstudent(stu,NULL);
tail = tail->next;
tail->next = NULL;
size++;
return true;
}
void Liststudent::show_all()const
{
cout << "snumber\tname\tage\tsex\tchinese\tmath\tenglish\ttotal\taverage"<<endl;
Linkstudent *temp = first->next;
while(temp != NULL)
{
temp->stu.showall();
temp = temp->next;
}
}
bool Liststudent::remove_n(char *n)
{
// if(empty()) return false;
Linkstudent *temp = first;
Linkstudent *dele;
while(temp->next != NULL)
{
if(!strcmp(n , temp->next->stu.get_n() ))
{
dele = temp->next;
temp->next = dele->next;
delete dele;
size--;
return true;
}
temp = temp->next;
}
return false;
}
bool Liststudent::remvoe_sn(char *sn)
{
Linkstudent *temp = first;
Linkstudent *dele;
while(temp->next != NULL)
{
if(!strcmp(sn , temp->next->stu.get_sn() ))
{
dele = temp->next;
temp->next = dele->next;
delete dele;
size--;
return true;
}
temp = temp->next;
}
return false;
}
Linkstudent * Liststudent::find_n(char *n)
{
// if(empty())
// return NULL;
Linkstudent *temp = first->next;
while(temp != NULL)
{
if(!strcmp(n , temp->stu.get_n() ))
return temp;
temp = temp->next;
}
return NULL;
}
Linkstudent * Liststudent::find_sn(char *sn)
{
// if(empty())
// return NULL;
Linkstudent *temp = first->next;
while(temp != NULL)
{
if(!strcmp(sn , temp->stu.get_sn() ))
return temp;
temp = temp->next;
}
return NULL;
}
void Liststudent::find_chinese(int score)
{
Linkstudent *temp = first->next;
while(temp != NULL)
{
if(score==temp->stu.get_chinese())
{temp->stu.showall();break;}
/*if(chinese temp->stu.get_chinese() ))
return temp;*/
temp = temp->next;
}
}
void Liststudent::find_math(int score)
{
Linkstudent *temp = first->next;
while(temp != NULL)
{
if(score==temp->stu.get_math())
{temp->stu.showall();break;}
/*if(chinese temp->stu.get_chinese() ))
return temp;*/
temp = temp->next;
}
}
void Liststudent::find_english(int score)
{
Linkstudent *temp = first->next;
while(temp != NULL)
{
if(score==temp->stu.get_english())
{temp->stu.showall();break;}
/*if(chinese temp->stu.get_chinese() ))
return temp;*/
temp = temp->next;
}
}
void Liststudent::sort_ascending(int choice)
{
Linkstudent *temp,*front,*p,*q;
for(int i=0;i<size-1;i++)
{
front=first;
p=front->next;
q=p->next;
for(int j=0;j<size-i-1;j++)
{
if(p->stu.get_key(choice)>q->stu.get_key(choice))
{
front->next=q;
temp=q->next;
q->next=p;
p->next=temp;
q=p->next;
front=front->next;
}
else
{
front=front->next;
p=p->next;
q=q->next;
}
}
}
}
int Liststudent::get_size()
{
return size;
}
void Liststudent::sort_descending(int choice)
{
Linkstudent *temp,*front,*p,*q;
for(int i=0;i<size-1;i++)
{
front=first;
p=front->next;
q=p->next;
for(int j=0;j<size-i-1;j++)
{
if(p->stu.get_key(choice)<q->stu.get_key(choice))
{
front->next=q;
temp=q->next;
q->next=p;
p->next=temp;
q=p->next;
front=front->next;
}
else
{
front=front->next;
p=p->next;
q=q->next;
}
}
}
}
void Liststudent::save_stuInfo()
{
ofstream of("studentInfo.txt",ios_base::out);
Linkstudent *p=first->next;
while(p->next)
{
p->stu.outfilestream(of);
p=p->next;
}
of<<p->stu.get_age()<<"\t"<<p->stu.get_ava()<<"\t"<<p->stu.get_chinese()<<"\t"<<p->stu.get_english()<<"\t"<<p->stu.get_math()<<"\t"<<p->stu.get_n()<<"\t"<<p->stu.get_sex()<<"\t"<<p->stu.get_sn()<<"\t"<<p->stu.get_tot();
of.close();
}
void Liststudent::read_stuInfo()
{
ifstream is("studentInfo.txt",ios::in);
Student *student;
if(!is)
{
ofstream os("studentInfo.txt",ios::out);
os.close();
return;
}
while(!is.eof())
{
student=new Student();
student->infilestream(is);
first->next = new Linkstudent(*student,first->next);
size++; //鏈表大小加1
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -