以下是某同学的成绩,通过间接寻址实现增加,删除,查询等功能
#include<iostream>
using namespace std;
# define MAX 100
class Node{
friend class List;
private:
int data;
Node* next;
};
class List{
public:
List();
List(int a[],int n);
~List();
int length();
int Get(int i);
int Locate(int x);
void Insert(int i,int x);
int Delete(int i);
void Print();
private:
Node*first,*total[MAX];
};
List::List(){
first=new Node;
first->next=NULL;
}
List::List(int a[],int n){ //头插法新建链表
if (n > MAX) throw("溢出");
Node*s;
int i;
first=new Node;
first->next=NULL;
for(i=0;i<n;i++)
{
s=new Node;
s->data=a[i];
s->ne