基本的線性表(順序表)

2021-10-04 03:05:41 字數 1039 閱讀 3627

首先建立乙個類庫(這裡我用的是datasruct),在類庫中建立乙個介面或者抽象類來定義線性表

具體操作如下:

public inte***ce ilinearlistwhere t:icomparable//定義了乙個介面ilinearlist和乙個泛型t(讓t實現icomparable的介面,可比較);

//得到線性表當前的長度;

t this [int index] //定義了乙個索引器,達到隨機訪問的目的;

void clear();//清空表中的元素;

bool isempty();//判斷表中的元素是否為空;

void insert(int index, t data);//插入操作(再index處插入t型別所給的資料)

void remove(int index);//移除操作;

int search(t data);//查詢操作;

}

順序表:利用順序儲存結構(即利用陣列)實現的線性表。

定義乙個類seqlist來實現上面定義的ilinearlist這個介面(泛型):

實現介面就要實現ilinearlist中定義的方法,所以在順序表這個類中寫如下**。**較長

此時順序表中的方法就寫完了,在主程式中引用一下你定義的這個類庫,並且在program.cs中引用這個命名空間。

最後得到執行結果與預想的一致:

線性表的基本操作(順序表)

實驗內容 建立順序表,實現求表的長度 遍歷表 查詢 插入和刪除元素 求前驅 求後繼等操作 實驗基本要求 進一步熟悉 turbo c 或者vc 環境 掌握線性表結構的基本操作 include using namespace std include include define maxsize 50 t...

順序表的基本運算 線性表

c語言實現順序表的插入 刪除 查詢運算 1 2 實現順序表的插入 刪除 查詢運算3 45 include 6 include 7 include 89 define maxsize 20 10 typedef int elemtype 1112 typedef struct seqlist 13 s...

線性表 順序表的基本操作

includeusing namespace std typedef long long ll const ll n 1000000 5 define maxsize 50typedef struct sqlist 基礎操作函式 初始化順序表函式,構造乙個空的順序表 void initlist sq...