c语⾔顺序表伪代码实现伪代码实现,顺序表
#include <stdio.h>
#include <stdlib.h>
typedef int ElemType;/*定义顺序表*/
typedef struct {c语言listinsert函数
ElemType *elem;
int length;
int listsize;
} SqList;/*初始化顺序表*/
void InitList(SqList *l){
l->length =0;
}int lnitList_Sq(SqList &L){
L.elem =(ElemType *)malloc(100*sizeof(ElemType));
if(!L.elem)
return0;
L.length =0;
L.listsize =100;
return1;
}/*插⼊并排序操作*/
int ListInsert_Sq(SqList &L,int i, ElemType e){
ElemType *newbase;
ElemType *q;
ElemType *p;if(i <1|| i > L.length +1)
return0;
if(L.length >= L.listsize){
newbase =(ElemType *)realloc(L.elem,(L.listsize +10)*sizeof(ElemType));
if(!newbase)
return0;
L.elem = newbase;
L.listsize +=10;
}
q =&(L.elem[i -1]);
for(p =&(L.elem[L.length -1]); p >= q;--p)
*(p +1)=*p;
*q = e;++L.length;return1;
}int main(){
int a[5]={1,2,4,5,6};
int  i;int temp =7;
SqList List;
lnitList_Sq(List);
for(i =1; i <=5; i++)
ListInsert_Sq(List, i, a[i -1]);
for(i =1; i <= List.elem[i -1]; i++);
for(i =1; i <= List.length; i++)
printf("%d", List.elem[i -1]);
i =4;ListInsert_Sq(List, i, temp);
printf("\n插⼊后的元素序列为:\n");
for(i =1; i <= List.length; i++)
printf("%d", List.elem[i -1]);
}

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。