typedef
int elemtype;
const
int maxsize =50;
typedef
struct
sqlist;
void
initlist
(sqlist *&)
;// 初始化線性表
void
destroylist
(sqlist *&)
;// 銷毀線性表
bool
listempty
(sqlist *);
// 判定線性表是否為空
intlistlength
(sqlist *);
// 獲得線性表長度
void
showlist
(sqlist *);
// 輸出線性表
bool
getelem
(sqlist *
,int
, elemtype &);
// 獲得第i個元素的值,儲存到e中
intlocateelem
(sqlist *
, elemtype)
;// 查詢元素e第一次出現的位置,不存在返回0
bool
listinsert
(sqlist *&,
int, elemtype)
;// 再第i個位置插入元素e
bool
listdelete
(sqlist *&,
int, elemtype &);
// 刪除第i個元素,並儲存到e中
void
initlist
(sqlist *
&l)void
destroylist
(sqlist *
&l)bool
listempty
(sqlist * l)
intlistlength
(sqlist * l)
void
showlist
(sqlist * l)
printf
("]\n");
}bool
getelem
(sqlist * l,
int i, elemtype &e)
intlocateelem
(sqlist * l, elemtype e)
bool
listinsert
(sqlist *
&l,int i, elemtype e)
bool
listdelete
(sqlist *
&l,int i, elemtype &e)
void
createlist
(sqlist *
&, elemtype ,
int)
;// 從陣列中建立線性表,時間複雜度o(n)
void
deleteelem1
(sqlist *
&, elemtype)
;// 刪除線性表中所有元素x,時間複雜度o(n),演算法1
void
deleteelem2
(sqlist *
&, elemtype)
;// 刪除線性表中所有元素x,時間複雜度o(n),演算法2
void
classify1
(sqlist *&)
;// 將鍊錶中所有值為奇數的元素移動到值為偶數的元素前,時間複雜度o(n),演算法1
void
classify2
(sqlist *&)
;// 將鍊錶中所有值為奇數的元素移動到值為偶數的元素前,時間複雜度o(n),演算法2,區間劃分法
void
createlist
(sqlist *
&l, elemtype a,
int n)
l -> length = i;
}void
deleteelem1
(sqlist *
&l, elemtype x)
l -> length -
= k;
}void
deleteelem2
(sqlist *
&l, elemtype x)
} l -
> length = k;
}void
classify1
(sqlist *
&l)}
}void
classify2
(sqlist *
&l)}
}}
順序表的建立及操作
1 線性表結構體的演算法 define maxsize maxlen maxlen表示線性表可能的最大資料元素數目 typedef int elemtype elemtype表示資料元素型別,此處定義為int typedef struct sqlist sqlist是資料型別 2 求表長 int l...
線性表的定義與操作 順序表
線性表的定義與操作 順序表 注 無main函式 define error 1 typedef int position typedef struct lnode list struct lnode 初始化 list makeempty 查詢 position find list l,elementt...
順序表的建立,實現及操作
include include include include include define max 1000 5 using namespace std typedef struct sqlist 定義線性表 void initlist sqlist l 初始化線性表 void destroyli...