資料結構 順序表的實現

2021-09-25 20:19:09 字數 1280 閱讀 4902

目錄

一、順序表

二、順序表對應功能的**示例

順序表所需要實現的一般功能

順序表的優缺點:

#define size 20

typedef struct sequencelist

*list;

list initlist()

bool isempty(list sl)

bool isfull(list sl)

bool insertlist(int n, list sl)

else if(isfull(sl)) return false;

/*插入*/

int pos;

for(pos=0; pos<=(sl->last); pos++)//獲得第乙個大於n的下標位置

int tmp_pos;

for(tmp_pos = sl->last; tmp_pos >= pos; tmp_pos--)

sl->data[pos] = n;

sl->last++;

return true;

}

bool dellist(int n, list sl)

else if(isempty(sl)) return false;

/*將傳來資料變成正數*/

n = -n;

/*刪除*/

int pos;

for(pos=0; pos<= sl->last; pos++)//找到要刪除的位置

int tmp_pos;

for(tmp_pos = pos; tmp_pos<= sl->last; tmp_pos++)

sl->last--;

return true;

}

void showlist(list sl)

/*列印順序表全部資料*/

int i;

for(i=0; i<=sl->last; i++)

printf("\n");

}

資料結構(順序表的實現)

include define max len 100 容器的最大存量 using namespace std 各種資料結構,無非 建構函式 初始化 什麼資料型別 插入 插入的位置和插入的元素 刪除 刪除那個元素 查詢 按值查詢還是按址查詢以及查詢的方向 遍歷 下標遍歷和迭代器遍歷 cout 順序表 ...

資料結構 順序表的實現

實現順序表的插入 刪除 檢視等操作。操作選單要求 插入 輸入插入的位置和資料,輸出插入後的資料 刪除 輸入要刪除的位置,輸出刪除後的資料 檢視 檢視當前順序表的資料 退出。include include define maxsize 50 typedef int elemtype define li...

c 實現順序表(資料結構)

pragma once 防止重複編譯 include include using namespace std template class type class seqlist bool isempty const public void push back const type x 尾插 此con...