#include<iostream>
using namespace std;
const int M=20;
struct Node
{
int data;
};
class Student
{
public:
Student();
Student(int a[],int n);
~Student(){}
int Length(){return length;}
int Get(int i);
int Delete(int i);
void Insert(int i,int x);
void Print();
private:
Node *first[M];
int length;
};
Student::Student()
{
for(int i=0;i<M;i++)
first[i]=NULL;
length=0;
}
Student::Student(int a[],int n)
{
for(int i=0;i<M;i++)
{
first[i]=new Node;
first[i]->data=a[i];
}
length=n;
}
int Student::Get(int i)
{
if(i<1||i>length)
throw"位置非法";
else return first[i-1]->data;
}
int Student::Delete(int i)
{
int x,j;
if(length==0)
throw"下溢";
if(i<1||i>length)
throw"位置非法";
x=first[i-1]->data;
for(j=i;j<length;j++)
first[j-1]->data=first[j]->data;
length--;
return x;
}
void Student::Insert(int i,int x)
{
int j;
if(length>=M)
throw"上溢";
if(i<1||i>length+1)
throw"位置非法";
for(j=length;j>=i;j--)
first[j]->data=first[j-1]->data;
first[i-1]->data=x;
length++;
}
void Student::Print()
{
int i;
for( i=0;i<length;i++)
{
cout<<endl<<"第"<<i+1<<"个学生成绩"<<first[i]->data<<" ";
}
}
void main()
{
int score[3]={90,60,85};
Student S(score,3);
cout<<"学生的成绩为:"<<endl;
S.Print();
cout<<endl<<endl<<"在位置2插入成绩70:"<<endl;
S.Insert(2,70);
S.Print();
cout<<endl<<endl<<"删除第三个学生的成绩:"<<endl;
S.Delete(3);
S.Print();
cout<<endl<<endl<<"位置2的成绩为:"<<endl;
cout<<S.Get(2)<<endl;
cout<<endl;
}