西电_C++_面向象程序设计_软件技术基础_课后答案 2.doc

西电_C++_面向象程序设计_软件技术基础_课后答案 2.doc

  1. 1、本文档共26页,可阅读全部内容。
  2. 2、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
  3. 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  4. 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
西电_C_面向象程序设计_软件技术基础_课后答案2

软件技术基础习题答案 习题3 四、1 int compare(SeqList*La,SeqList*Lb) { int i; i=1; while(i=La-lasti=Lb-Last La-data[i]==Lb-data[i]) i++; if(i=La-lastjLb-last|| La-data[i]Lb-data[i]) return 1; //AB if(iLa-lastj=Lb-last|| La-data[i]Lb-data[i]) return -1; //AB if(iLa-lastjLb-last) return 0; //A=B } 四、2 (1)顺序表 int invert(SeqList*L) { int i=1; datatype temp; while(i=L-last/2) { temp=L-data[i]; L-data[i]=L-data[L-last-i+1]; L-data[L-last-i+1]=temp; } } (2)链表 void invert (linklist*head) { linklist*p,*q,*r; p=head-next; q=p-next; while(q!=NULL) { r=q-next; q-next=p; p=q; q=r; } head-next-next=NULL; head-next=p; } 四、5 void mergelist(Linear_list*La,Linear_list*Lb,Linear_list*Lc) { Lc=(Linear_list*)malloc(sizeof(Linear_list)); //产生C表的头结点 头插法 Lc-next=NULL; while(La-next!=NULLLb-next!=NULL) //La、Lb均非空 if(La-next-data=Lb-next-data) { p=La-next; La-next=La-next-next; insert(Lc,p); } else { p=Lb-next; Lb-next=Lb-next-next; insert(Lc,p); } while(La-next!=NULL) { p=La-next; La-next=La-next-next; insert(Lc,p); } while(Lb-next!=NULL) { p=Lb-next; Lb-next=Lb-next-next; insert(Lc,p); } }//O(Length(La)+Length(Lb)) void insert(Linear_list*Lc,Linear_list*p) { p-next=Lc-next; Lc-next=p; }//O(1) 四、8 void deleteFront(Link*s) { Link*p=s,*q; while(p-next-next!=s)p=p-next; q=p-next; p-next=s; free(q); } 习题4 四、1 int symmetry(linklist*head,stack*s) //具有头结点的单链表中存放有一个字符串,每个结点的数据域存放一个字符。 //head为单链表的头指针,s为栈的结构体指针 { int n=length(head)/2; linklist*p=head-next ; datatype x; for(int i=0;in;i++){ push(s,p-data); p=p-next ; } if(length(head)%2==1) p=p-next; while(p!=NULL){ x=pop(s) ; if (x==p-data ) p=p-next; else return 0; } return 1; } 四、3 void delete(Stack*s) { Stack*temp; datatype x; InitS(temp); while(!EmptyS(s)) { x=Pop(s); if(x!=m) Push(temp,x); } while(!Empty(temp)) Push(s,Pop(temp)); } 四、4 int corr

文档评论(0)

chengben002424 + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档