線性表順式模板

2021-10-01 11:36:51 字數 1380 閱讀 9041

#include#includeusing namespace std;

#define maxsize 100

#define ok 1

#define error 0

#define overflow -2

typedef struct sqlist;

int initlist(sqlist &l)

void showlist(sqlist &l)

cout << endl;

}void findmax(sqlist &l)

} cout << m << endl;

}int insertlist(sqlist &l)

if (l.length == maxsize)

cout << "您要插入的數字為:" << endl;

cin >> e;

for (int j = l.length - 1; j >= x - 1; j--)

l.data[j + 1] = l.data[j];

l.data[x - 1] = e;

l.length++;

cout << "插入新數字之後的順序表為:" << endl;

showlist(l);

return ok;

}int deleteelem(sqlist &l)

for (int j = x - 1; j < l.length - 1; j++)

l.data[j] = l.data[j + 1];

l.length--;

cout << "刪除數字之後的順序表為:" << endl;

showlist(l);

return ok;

}void upranklist(sqlist &l)

} }cout << "該陣列按公升序排列後為:" << endl;

showlist(l);

}int main()

cout << "請輸入下列選項前的字母對該陣列進行相應操作。" << endl

<< "a.顯示出該順序表" << endl

<< "b.找出該組數中的最大值" << endl

<< "c.在該順序表中插入新資料" << endl

<< "d.刪除某個資料" << endl

<< "e.將該順序表按公升序排列" << endl;

char choice;

do } while ((choice = 'a') && (choice = 'b') && (choice = 'c') && (choice = 'd') && (choice = 'e'));

system("pause");

return 0;

}

線性表的標準模板

include include include definelistincreasment 100 每次分配元素的個數 define listsize 10 順序儲存的最大個數 define overflow 1 define ok 1 typedef int elemtype typedef st...

資料結構Week2 1 線性表的順式和鏈式表達

目錄 1 問題引入 如何表示多項式 2 線性表 2.1主要操作實現 2.2線性表的鏈式儲存實現 2.3總結 3.問題引入 如何表示二元多項式 3.1廣義表 3.2多重鍊錶 方法一 陣列分量對應多項式各項 a i 表示第 i 項數的係數,下表表示次數 缺點 陣列不能太大,浪費空間 方法二 順序儲存結構...

線性表 順序表與單鏈表(模板)

順序表 線性表的順序儲存結構,靜態儲存分配,通常用一位陣列來實現 include using namespace std const int maxsize 100 template typename t class seqlist template typename t seqlist seqli...