線性表的順序實現

2022-06-16 05:06:11 字數 1503 閱讀 4078

線性表的順序表示和實現

#include "

stdio.h

"#define true 1

#define false 0

#define list_init_size 30

#define list_increment 10typedef

intelemtype;

typedef

struct

sqlist;

/*初始化乙個線性表

*/int initlist_sq(sqlist *l)

/*銷毀乙個線性表

*/void destroylist(sqlist *l)}/*

清空線性表

*/void clearlist(sqlist *l)

/*判斷是否為空表

*/int

listempty(sqlist l)

/*返回元素個數

*/int

listlength(sqlist l)

/*返回某一元素的值

*/int getelem(sqlist l,int i,elemtype *e)

/*比較兩個元素

*/int

compare(elemtype x,elemtype y)

/*返回線性表中第乙個與e滿足關係compare()的元素的位序

*/int

locateelem(sqlist l,elemtype e)

return

false;}/*

若cur_e是線性表的元素,且不是第乙個,則返回它的前驅

*/int priorelem(sqlist l,elemtype cur_e,elemtype *e)}/*

若cur_e是線性表的元素,且不是最後乙個,則返回它的後繼

*/int nextelem(sqlist l,elemtype cur_e,elemtype *e)}/*

*/int listinsert(sqlist *l,int

i,elemtype e)

p=&(l->elem[i-1

]);

for(q=&(l->elem[l->length-1]);q>=p;--q)

*(q+1)=*q;

*p=e;

++(l->length);}/*

刪除線性表的第i個元素,並用e返回其值

*/int listdelete(sqlist *l,int i,elemtype *e)

/*兩個線性表的合併

*/void mergelist(sqlist la,sqlist lb,sqlist *lc)

else

}while(i<=la_len)

while(j<=lb_len)

}void

main()

執行後結果:

線性表順序實現

線性表實現,建立表,插入元素,刪除元素,銷毀表,表的遍歷,表的並集交集差集。不斷更新中。include include include include define list init size 100 初始大小 define error 0 define listincrement 10 增量大小...

線性表的順序實現

include using namespace std 線性表的順序儲存結構 const int maxlistsize 100 class list 構造乙個空線性表 void clear bool isempty 判斷是否為空,若為空,返回true,否則返回false intgetelem in...

線性表的順序實現

include include define maxsize 50 typedef char elemtype typedef struct elemtype elem maxsize int length sqlist 順序表型別定義 void initlist sqlist l 初始化順序表l ...