1.单链表实现学生成绩
源代码:
- #include
- using namespace std;
- template
- struct Node
- {
- T data;
- Node *next;
- };
- template
- class Score
- {
- public:
- Score(); //无参构造函数,建立只有头结点的空链表
- Score(T a[],int n); //有参构造函数,建立有n个元素的单链表
- ~Score(); //析构函数
- int Length(); //求单链表的长度
- T Get(int i); //按位置查找,在单链表中查找第i个结点的元素值
- int Locate(T x); //按值查找,在单链表中查找值为x的元素序号
- void Insert(int i,T x); //在第i个位置插入元素值为x的结点
- T Delete(int i); //在单链表中删除第i个结点
- void PrintList();
- private:
- Node *first;
- };
- template
- Score::Score()
- {
- first=new Node; //生成头结点
- first->next=NULL; //头结点的指针域置空
- }