
#include <iostream>
using namespace std;
const int MAXSIZE = 20;
const int ERROR = 0;
const int OK = 1;
typedef int Status;
typedef struct Student
{
int number;
int grade;
Student() {
}
Student(int num, int g):number(num), grade(g) {
}
}Student;
class SqList
{
public:
SqList();
~SqList();
Status ListInsert(int i, Student &e);
Status ListDelete(int i, Student &e);
void OutoutList() const;
void InputList();
void MergeList(const SqList &La, const SqList &Lb);
private:
Student *elem;
int length;
int listSize;
};
ostream& operator << (ostream& os, const Student& x)
{
return os << '(' <<x.number << ',' << x.grade << ')';
}
SqList::SqList()
{
elem = new Student[MAXSIZE];
length = 0;
listSize = MAXSIZE;
}
SqList::~SqList()
{
delete[] elem;
}
Status SqList::ListInsert(int i, Student &e)
{
Student *p;
if(i<1 || i>length+1)
{
return ERROR;
}
if(length >= MAXSIZE)
{
Student *newbase = new Student[MAXSIZE*2];
if(!newbase)
{
cerr << "内存分配错误!" <<endl;
return ERROR;
}
p = elem;
elem = newbase;
for(int i=0; i<length; i++)
{
elem[i] = p[i];
}
listSize = MAXSIZE * 2