一、实验目的
巩固线性表的数据结构的存储方法和相关操作,学会针对具体应用,使用线性表的相关知识来解决具体问题。
二、实验内容
建立一个有n个学生成绩的静态链表,n的大小由自己确定,实现数据的对表进行插入、删除、查找等操作。分别输出结果。
三、算法实现
#include
using namespace std;
const int MAX_SIZE=100;
struct node{
float score;
int next;
};
class Score_staticLink{
private:
node score[MAX_SIZE];
int first,avail;
public:
Score_staticLink();
Score_staticLink(float a[],int n);
~Score_staticLink(){}
float getValue(int index);
void locate(float x);
void insert(int index,float x);
float _delete(int index);
void print();
};
Score_staticLink::Score_staticLink(){
first=0;
score[0].next=-1;
avail=1;
int p=avail;
for(int i=2;i
MAX_SIZE) throw"参数非法!\n";
first=0;
int p=0;
for(int i=1;i
MAX_SIZE) throw"查找位置非法!\n\n";
if(score[first].next==-1) throw"成绩为空!\n\n";
int count=0,p=first;
while(p!=-1&&count++
MAX_SIZE) throw"插入位置非法!\n\n";
int p=first,count=1;
while(p!=-1&&count++
MAX_SIZE) throw"删除位置非法!\n\n"; int p=first,count=1; while(p!=-1&&count++
四、运行结果
异常调试: