软件技术基础课后答案周大为西电.pdfVIP

  • 103
  • 0
  • 约1.38万字
  • 约 25页
  • 2018-11-06 发布于江苏
  • 举报
软件技术基础习题答案 习题3 四、1 intcompare(SeqList*La,SeqList*Lb) { inti; 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]) return1;//AB if(iLa-lastj=Lb-last|| La-data[i]Lb-data[i]) return-1;//AB if(iLa-lastjLb-last) return0;//A=B } 四、2 (1)顺序表 intinvert(SeqList*L) { 1 inti=1; datatypetemp; 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; } 2 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); 3 } 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 voiddeleteFront(Link*s) 4 { Link*p=s,*q; while(p-next-next!=s)p=p-next;

文档评论(0)

1亿VIP精品文档

相关文档