定義順序表,獲得順序表長度,第i個元素,元素x的位置,刪除元素y
#include
#include
#include
using namespace std;
#define maxsize 100
typedef
int elemtype;
//假設順序表中所有元素為int型別
typedef
struct
sqlist;
void
initlist
(sqlist &l)
//由於l要回傳給實參,所以用引用型別
void
destroylist
(sqlist l)
intgetlength
(sqlist l)
intgetelem
(sqlist l,
int i, elemtype &e)
//取元素值並返回1
}int
locate
(sqlist l, elemtype x)
intinselem
(sqlist &l, elemtype x,
int i)
//指定位置插入
intdelelem
(sqlist &l,
int i)
//刪除
void
displist
(sqlist l)
//輸出
void
main()
測試示例:
資料結構 順序表
順序表的特徵 1由唯一的表名標識 2佔據一塊連續的儲存空間 3資料順序存放,元素之間有先後關係 定義動態的順序表 define maxsize 100 typedef struct sqlist 這個結構體型別存放的是順序表的資訊和順序表的資料 初始化順序表 void initsqlist sqli...
資料結構 順序表
順序表示最簡單的乙個資料結構,直接貼 吧,因為比較簡單。include include typedef struct sqlist sqlist void initlist sqlist l l length 0 void getelem sqlist l 初始化 l length j printf...
資料結構順序表
include include include include include include include include include include include include include include using namespace std define maxn 100000...