順序表的基本功能(C語言實現)

2021-10-18 12:17:50 字數 2369 閱讀 1454

#include

#include

#define maxsize 100

#define true 1

#define ok 1

#define false 0

#define error 0

#define overflow -1

typedef

int elemtype;

typedef

int status;

typedef

struct

sqlist;

status ininlist_sq

(sqlist &l)

else

printf

("初始化成功\n");

l.length =0;

}status destorylist_sq

(sqlist &l)

status clearlist_sq

(sqlist &l)

status getelem_sq

(sqlist l)

status emptylist_sq

(sqlist l)

else

}status getlist_sq

(sqlist l,

int i,elemtype &e)

status locateelem_sq

(sqlist l,elemtype e)

status insertlist_sq

(sqlist &l,

int i,elemtype e)

status displaylist_sq

(sqlist l)

status deletelist_sq

(sqlist &l,

int i)

intmain()

//插入

printf

("***********************\n");

displaylist_sq

(l);

//顯示

printf

("***********************\n");

printf

("請輸入您要刪除第幾條資料\n");

scanf

("%d"

,&x)

;deletelist_sq

(l,x)

;//刪除

displaylist_sq

(l);

//顯示

printf

("***********************\n");

e=getelem_sq

(l);

//求線性表長度

printf

("線性表長度為:%d\n"

,e);

printf

("***********************\n");

printf

("請輸入您要查詢第i個資料\n");

scanf

("%d"

,&i)

; m=

getlist_sq

(l,i,e)

;//順序表取值

printf

("第%d個資料為:%d\n"

,i,m)

;printf

("***********************\n");

printf

("請輸入您要查詢的資料\n");

scanf

("%d"

,&e)

; j=

locateelem_sq

(l,e)

;//線性表查詢

printf

("%d資料是第%d條資料\n"

,e,j)

;printf

("***********************\n");

clearlist_sq

(l);

//清空

printf

("***********************\n");

emptylist_sq

(l);

//判斷是否為空

printf

("***********************\n");

destorylist_sq

(l);

//銷毀

printf

("***********************\n");

}

執行程式結果

C語言實現順序佇列的基本功能

front指向佇列的隊頭元素,rear指向隊尾元素的下乙個。因為鏈式佇列有頭節點,順序佇列沒得頭節點 為了判斷是否未滿,最後乙個空間不放元素 include include define max 100 struct book typedef struct node sqqueue intis em...

線性表基本功能的c語言實現

include define false 0 define ok 1 define maxsize 10 定義了線性表的結構 typedef struct sqlist 初始化線性表 int initlist sqlist l 向線性表插入資料 int listinsert sqlist l,int...

c語言實現線性表的基本功能

include include 區別c和c 1.c語言是 includec 是 include是完全物件導向 c 是半物件導向 出現類 既面向過程又物件導向 c語言是面向過程 語言原始檔拓展名可以是cpp c plus plus c 向下相容的 define listsize 100 常量 type...