??上一篇介紹了順序表的有關定義及其及其簡單的插入,洗掉,按值查找操作,這一篇將介紹順序表的其他操作,
1.順序表的初始化
??靜態存盤順序表初始化:
void Initlist(SqList &L){
for(int i = 0;i < L.MaxSize;i++){
L.data[i] = 0; //所有資料元素初值設為0
}
L.length = 0; //資料元素初始長度為0,覆寫臟資料
}
??動態存盤順序表初始化:
void Initlist(SeqList &L){
//用malloc申請一片地址連續的存盤空間
L.data = https://www.cnblogs.com/ITXiaoAng/p/(ElemType*)malloc(sizeof(ElemType) * InitSize);
L.length = 0;
L.MaxSize = InitSize;
}
2.動態順序表增加陣列長度
bool IncreaseList(SeqList &L,int len){
ElemType *p = L.data;
L.data = https://www.cnblogs.com/ITXiaoAng/p/(ElemType*)malloc(sizeof(ElemType) * (L.MaxSize + len));
for(int i = 0;i < L.length;i++){
L.data[i] = p[i];
}
L.MaxSize = L.MaxSize + len;
free(p);
}
3.順序表的按位查找
ElemType GetElem(SeqList L,ElemType e){
return L.data[i-1];
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/144607.html
標籤:其他
