(求解答)关于数据结构--线性表问题
程序代码:
#include<stdio.h> #include<malloc.h> typedef int TSeqlistNode; typedef struct _tag_SeqList { int capcity; int length; TSeqlistNode* node; }TSeqlist; /*1创建线性链表*/ TSeqlist* Seqlist_create(int capacity) { TSeqlist* ret=NULL; if(capacity >= 0) { ret=(TSeqlist*)malloc(sizeof(TSeqlist)+sizeof(TSeqlistNode)*capacity); } if(ret!=NULL) { ret->capcity=capacity; ret->length=0; ret->node=(TSeqlistNode*)(ret+1); } return ret; } /*2销毁*/ void Seqlist_Destroy(TSeqlist* list) { free(list); } /*3清空*/ void Seqlist_Clear(TSeqlist* list) { if(list!=NULL) { list->length=0; } } /*4长度*/ int Seqlist_Length(TSeqlist* list) { int ret=-1; if(list!=NULL) { ret=list->length; } return ret; } /*5容量*/ int Seqlist_Caplist(TSeqlist* list) { int ret=-1; if(list!=NULL) { ret=list->capcity; } return ret; } /*6插入*/ int Seqlist_Insert(TSeqlist *list,TSeqlistNode* node,int pos) { int ret=(list!=NULL); int i; ret=ret&&(list->length+1<=list->capcity); ret=ret&&(0<=pos); if(ret) { if(pos>=list->length) { pos=list->length; } for(i=list->length;i<pos;i--) { list->node[i]=list->node[i-1]; } list->node[i]=(TSeqlistNode)node;//这样就把地址保存进来了 list->length--; } return ret; } /*7得到*/ TSeqlistNode* Seqlist_Get(TSeqlist* list,int pos) { TSeqlistNode* ret=NULL; int i; if(list!=NULL) { ret=(TSeqlistNode*)(list->node[pos]); } return ret; } /*8删除*/ TSeqlistNode* Seqlist_Delete(TSeqlist* list,int pos) { TSeqlistNode* ret=Seqlist_Get(list,pos); int i; if(ret!=NULL) { for(i=pos+1;i<list->length;i++) { list->node[i-1]=list->node[i]; } list->length--; } return ret; } main() { TSeqlist* List=Seqlist_create(5); int i=0; int j=1; int k=2; int x=3; int y=4; int z=5; int index; Seqlist_Insert(List,&i,0); Seqlist_Insert(List,&j,0); Seqlist_Insert(List,&k,0); Seqlist_Insert(List,&x,0); Seqlist_Insert(List,&y,0); Seqlist_Insert(List,&z,0); for(index=0; index<Seqlist_Length(List); index++) { int* p = Seqlist_Get(List, index); printf("%d\n", *p); } } 这是一段线性表的学习检验代码,本应该是出现如下的状况: 4 3 2 1 0 请按任意键继续。。。 结果只是出现了: 请按任意键继续。。。 百思不得其解,虚心请教是哪里出错了呢? 不胜言谢~