創建文件命名爲sqlist.h
#ifndef SQLIST_H
#define SQLIST_H
typedef int ElemType;
class SqList
{
public:
SqList(); // 無參構造函數,建立空的順序表
SqList(ElemType array[], int len); // 有參構造函數,構建len個數據元素的順序表
~SqList(); // 析構函數
ElemType Get(int index); // 按位置查找
int Find(ElemType x); // 按值查找
bool Insert(int index, ElemType x); // 插入操作
bool Delete(int index); // 刪除操作
void PrintList(); // 打印順序表
private:
ElemType *elem; // 存儲空間基址
int length; // 當前長度
int maxLen; // 存儲空間的大小,根據第一次構造確定
};
/*
* 單鏈表
* 採用尾插法
*/
struct Node
{
ElemType data;
Node *next;
};
class LinkList
{
public:
LinkList(); // 無參構造函數,建立空的單鏈表
LinkList(ElemType array[], int len); // 有參構造函數,構建含有len個Node節點的鏈表
~LinkList();