實驗內容:
建立順序表,實現求表的長度、遍歷表、查詢、插入和刪除元素、求前驅、求後繼等操作;
實驗基本要求:
進一步熟悉
turbo c
或者vc
++環境;
掌握線性表結構的基本操作
#include
using namespace std;
#include
#include
#define maxsize 50
typedef char elemtype;
typedef struct
sqlist;
void initlist(sqlist *&l) //初始化線性表
l->length=x; //置空線性表長度為0
}void destroylist(sqlist *l) //清空線性表
bool listempty(sqlist *l) //判線性表是否為空表
int listlength(sqlist *l) //求線性表的長度
void displist(sqlist *l) //輸出線性表
elemtype getelem(sqlist *l,int i,elemtype &e) //求線性表中某個資料元素值
int locateelem(sqlist *l, elemtype e) //按元素值查詢
bool listfull(sqlist *l) //判斷線性表是否為滿
bool listinsert(sqlist *&l,int i,elemtype e) //插入資料元素
bool listdelete(sqlist *&l,int i,elemtype &e) //刪除資料元素
elemtype sqlistprior(sqlist *l,elemtype e) /*求順序表中元素的前驅*/
else if
(i<=l->length-1)
return(l->data[i-1]);
else
}elemtype sqlistnext(sqlist *l,elemtype e) /*求順序表中元素的後繼*/
else if(ilength-1)
return(l->data[i+1]);
else
return 0;
}
線性表 順序表的基本操作
includeusing namespace std typedef long long ll const ll n 1000000 5 define maxsize 50typedef struct sqlist 基礎操作函式 初始化順序表函式,構造乙個空的順序表 void initlist sq...
順序線性表的基本操作
這個 可以對順序線性表進行查詢 刪除 插入 建立等基本操作。include struct node typedef node list,lnode void printlist list l 列印線性表 void creatlist list l,int n 建立線性表 int getelem li...
線性表之順序表基本操作
sqheader.h ifndef sqheader h included define sqheader h included 順序表的儲存結構 define maxsize 50 typedef char elemtype typedef struct sqlist endif sqheader...