#include"List.h"
List::List()
{
count = 0;
head = NULL;
}
List::~List()
{
student *p, *q;
p = head;
for(int i = 0;i != count;i ++)
{
q = p->next;
delete p;
p = q;
}
count = 0;
head = NULL;
}
Error_code List::insert(int position, const std::string nam, const std::string num,
const int Chi, const int math, const int Eng, const int data)
{
if (position < 0 || position > count)
return range_error;
student *new_student, *previous, *following;
if (position > 0)
{
previous = set_position(position - 1);
following = previous->next;
}
else
following = head;
new_student = new student(nam, num, Chi, math, Eng, data, following);
if (new_student == NULL)
return overflow;
if (position == 0)
head = new_student;
else
previous->next = new_student;
count++;
return success;
}
student* List::set_position(int position) const
{
student *q = head;
for (int i = 0; i < position; i++)
{
q = q->next;
}
return q;
}
void List::insertion_sort()
{
student *first_unsorted,
*last_sorted,
*current,
*trailing;
if(head!=NULL)
{
last_sorted = head;
int n = this->count;
for(int i=1 ;i<n;i++)
{
first_unsorted = last_sorted->next;
if(first_unsorted->total > head->total)
{
// Insert *first_unsorted at the head of the sorted list:
last_sorted->next = first_unsorted->next;
first_unsorted->next = head;
head = first_unsorted;
}
else
{
trailing = head;
current = trailing->next;
// Search the sorted sublist to insert *first_unsorted:
while(first_unsorted->total < current->total){
trailing = current;
current = trailing->next;
}
// *first_unsorted now belongs between *trailing and *current
if(first_unsorted==current)
last_sorted = first_unsorted; // already in right position
else
{
last_sorted->next = first_unsorted->next;
first_unsorted->next = current;
trailing->next = first_unsorted;
}
}
}
}
}
void List::traverse(void (*visit)(std::string &num,std::string &name, int &total, int &chinese,int &math, int &english, int &datastr))
{
student *q;
q = head;
for (int i = 0;i != count;i ++)
{
(*visit)(q->number,q->name,q->total,q->Chinese,q->Math,q->English,q->DataStruction);
q = q->next;
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
统计成绩.rar (23个子文件)
统计成绩
utility.asp 0B
统计成绩.dsp 4KB
统计成绩.dsw 524B
List.cpp 2KB
统计成绩.ncb 81KB
student.cpp 327B
Script1.rc 3KB
utility.h 193B
resource.h 411B
main.cpp 2KB
统计成绩.plg 1KB
List.h 558B
student.h 494B
Debug
student.obj 34KB
统计成绩.pdb 1.36MB
vc60.idb 153KB
main.obj 260KB
统计成绩.exe 544KB
统计成绩.pch 1.96MB
统计成绩.ilk 789KB
vc60.pdb 132KB
List.obj 38KB
统计成绩.opt 50KB
共 23 条
- 1
资源评论
- x3540645682013-05-09可以运行啊 有截图。。。
- Anxs13142012-09-19怎么运行不了?
- AIR19972017-12-22下来试试先
ALihexingyu
- 粉丝: 0
- 资源: 3
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功