logo资料库

华南农业大学数据结构上机题目答案.doc

第1页 / 共184页
第2页 / 共184页
第3页 / 共184页
第4页 / 共184页
第5页 / 共184页
第6页 / 共184页
第7页 / 共184页
第8页 / 共184页
资料共184页,剩余部分请下载后查看
这是广东省重点大学华南农业大学软件学院 2012 届《数据结构》 的上机习题答案,全部由本人手打,经上机验证,全部通过,特 地上传供广大同学参考。非华南农业大学的学生亦可参考,对学 习数据结构以及程序设计颇有益处。 关于华南农业大学软件工程 【培养目标】培养具有良好的综合素质、良好的职业道德、 扎实的软件理论和软件工程专业基础知识,并且具有良好的软件 设计与实现能力、良好的项目管理能力、良好的交流与组织协调 能力、较强的参与国际竞争能力和创新能力的软件工程专业人 才。 【就业方向】软件工程专业的学生毕业后,能够从事信息产 业相关的科学研究与软件设计工作,可以继续攻读相关学科的硕 士学位研究生,或到国内外软件公司、研究开发中心、国家机关、 企事业从事信息系统的设计、开发或管理工作。
2012 届华南农业大学 数据结构上机答案 1.1 顺序线性表的基本操作 #include #include #define OK 1 #define ERROR 0 #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define ElemType int typedef struct { int *elem,length,listsize; }SqList; int InitList_Sq(SqList &L) { L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemT ype)); L.length=0;
L.listsize=LIST_INIT_SIZE; return OK; } int Load_Sq(SqList &L) { int i; if(L.length==0) printf("The List is empty!"); else { } printf("The List is:"); for(i=0;iL.length+1)
return ERROR; ElemType *newbase,*q,*p; if(L.length>=L.listsize) { newbase=(ElemType*)realloc(L.elem,(L.listsize+LISTIN CREMENT)*sizeof(ElemType)); L.elem=newbase; L.listsize+=LISTINCREMENT; } q=&(L.elem[i-1]); for(p=&(L.elem[L.length-1]);p>=q;--p) *(p+1)=*p; *q=e; ++L.length; return OK; } int ListDelete_Sq(SqList &L,int i,int &e) { ElemType *q,*p; if(i<1||i>L.length)
return ERROR; p=&(L.elem[i-1]); e=*p; q=L.elem+L.length-1; for(++p;p<=q;p++) *(p-1)=*p; L.length--; return OK; } int main() { SqList T; int a,i; ElemType e,x; if(InitList_Sq(T)) { } printf("A Sequence List Has Created.\n"); while(1) { printf("1:Insert element\n2:Delete element\n3:Load
all elements\n0:Exit\nPlease choose:\n"); scanf("%d",&a); switch(a) { case 1: scanf("%d%d",&i,&x); if(!ListInsert_Sq(T,i,x)) printf("Insert Error!\n"); else printf("The Element %d is Successfully Inserted!\n",x); break; case 2: scanf("%d",&i); if(!ListDelete_Sq(T,i,e)) printf("Delete Error!\n"); else printf("The Element %d is Successfully Deleted!\n",e); break; case 3: Load_Sq(T); break; case 0: return 1; }
} } 1.2 合并顺序表 #include #include #define OK 1 #define ERROR 0 #define LIST_INIT_SIZE 100 #define LISTINCREMENT 10 #define ElemType int typedef struct { int *elem,length,listsize; }SqList; int InitList_Sq(SqList &L) { L.elem=(ElemType*)malloc(LIST_INIT_SIZE*sizeof(ElemT ype)); L.length=0; L.listsize=LIST_INIT_SIZE;
return OK; } int Load_Sq(SqList &L) { } int i; for(i=0;i
分享到:
收藏