一.实验目的
巩固线性表的数据结构的存储方法和相关操作,学会针对具体应用,使用线性表的相关知识来解决具体问题。
二..实验内容
建立一个由n个学生成绩的顺序表,n的大小由自己确定,每一个学生的成绩信息由自己确定,实现数据的对表进行插入、删除、查找等操作。分别输出结果。
(用双向链表来实现)。
三..源代码
//IndirectList.h文件
#include<iostream>
using namespace std;
const int MaxSzie = 100;
template<class T>
struct Node
{
T data;
Node *next;
};
template<class T>
class IndirectList
{
public:
IndirectList(); //无参构造函数
IndirectList(T b[], int n); //有参构造函数,插入长度为n的单链表
~IndirectList();
int Length(); //返回单链表的长度
T Get(int i); //按位查找,查找第i个节点的元素
int Locate(T x); //按值查找,查找链表中第一个值为x的元素,并返回序号
bool Insert(int i, T x); //插入元素,在第i个位置插入值x
bool Delete(int i); //删除节点,删除第i个节点
bool InsertHead(T x); //头插法插入节点
bool InsertTail(T x); //尾插法插入节点
void ListTraverse(); //正向遍历节点
bool changeList(int i, T x); //改变某一结点的值 i为节点的位置,x为替换的值
private:
Node<T> *first;
int m_Length;
Node<T> *a[MaxSzie];
};
template<class T>
IndirectList<T>::IndirectList()
{
for (int i = 0; i < MaxSzie; i++)
{
a[i] = null;
m_Length = 0;
}
}
template<cla