資料結構之順序表的基本操作(c語言版)

2021-10-04 12:12:17 字數 1242 閱讀 3331

#include

#include

#define maxsize 50

typedef

struct

sqlist;

//插入

bool listinsert

(sqlist *l,

int i,

char e)

//刪除

bool listdelete

(sqlist *l,

int i,

char

*e) l->length--

;return true;

}//按值查詢

intlocateelem

(sqlist l,

char e)

return0;

}int

main()

getchar()

;printf

("您輸入的順序表為:\n");

for(i =

0;i < sq.length;i++

)printf

("\n請輸入要 插入的值和位置,以空格分隔");

scanf

("%c"

,&num)

;scanf

("%d"

,&i)

;//printf("%c%d",num,i);

listinsert

(&sq,i,num)

;printf

("插入後的順序表為:");

for(i =

0;i < sq.length;i++

)printf

("\n請輸入要刪除的元素的位置\n");

getchar()

;scanf

("%d"

,&i)

;listdelete

(&sq,i,

&num)

;printf

("刪除後的順序表為\n");

for(i =

0;i < sq.length;i++

)getchar()

;printf

("\n請輸入查詢的元素:");

scanf

("%c"

,&num)

; i =

locateelem

(sq,num)

;printf

("%d"

,i);

}

資料結構 順序表的基本操作

計算機中線性表的存放結構主要有兩種 順序儲存結構和鏈式儲存結構。採用前者存放方式的線性表是順序表,採用後者的就是我們平時所說的鍊錶 線性鍊錶 這裡先對順序表的一些基本操作進行歸納和總結,鍊錶的將在後面的文章中歸納總結。順序表的表示,一般都是借助一維陣列。c 語言定義其結構如下 const int m...

資料結構 順序表的基本操作

main include include define true 1 define error 0 define ok 1 define false 0 define overflow 2 typedef int status typedef int elemtype define list ini...

資料結構 順序表的基本操作

老規矩先來看一下題目 本題要求實現順序表元素的增 刪 查詢以及順序表輸出共4個基本操作函式。l是乙個順序表,函式status listinsert sq sqlist l,int pos,elemtype e 是在順序表的pos位置插入乙個元素e pos應該從1開始 函式status listdel...