測試用例:#include
#include
#include
#define maxsize 100
#define ok 1
#define error 0
#define overflow -2
typedef
int status;
using
namespace std;
//定義順序表的儲存結構
typedef
struct
sqlist;
//將順序表初始化
status initlist
(sqlist &l)
//建立順序表
status createlist
(sqlist &l)
}return ok;
}//順序表的清空
void
clearlist
(sqlist &l)
//順序表的銷毀
void
destorylist
(sqlist &l)
//判斷順序表是否為空
status isempty
(sqlist l)
//在順序表指定位置插入元素
status listinsert
(sqlist &l,
int i ,
int e)
l.elem[i-1]
=e;//在第i個位置上插入元素
l.length++
;//表長度加一
return ok;
}//刪除順序表指定位置元素
status listdelete
(sqlist &l,
int i,
int e)
--l.length;
//表長度減一
return ok;
}//求兩個集合的交集
void
listintersection
(sqlist &la,sqlist &lb,sqlist &lc)
} lc.length=k;
//最後迴圈結束,c表的長度就是k
}//求兩個集合的並集
void
mergelist
(sqlist &la,sqlist &lb,sqlist &lc)
lc.length=k;
//最後迴圈結束,c表的長度就是k
}//求兩個集合的差集
void
subtract
(sqlist &la,sqlist &lb,sqlist &lc)
lc.length=k;
//最後迴圈結束,c表的長度就是k
}void
show()
intmain()
cout<<
"請輸入線性表中的元素(以-1結束):"
<
createlist
(l)==1)
//建立線性表
cout<<
"建立成功"
<
else
show()
; cin>>x;
while
(x>0)
else
if(x==2)
else
if(x==3)
else
if(x==4)
else
if(x==5)
else
if(x==6)
else
if(x==7)
else
if(x==8)
else
if(x==9)
} cout<<
"請輸入操作碼:"
; cin>>x;
}return0;
}
資料結構 順序表的基本操作
計算機中線性表的存放結構主要有兩種 順序儲存結構和鏈式儲存結構。採用前者存放方式的線性表是順序表,採用後者的就是我們平時所說的鍊錶 線性鍊錶 這裡先對順序表的一些基本操作進行歸納和總結,鍊錶的將在後面的文章中歸納總結。順序表的表示,一般都是借助一維陣列。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...