数据结构算法与数据结构复习.ppt
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_1.gif)
![资源得分’ title=](/images/score_05.gif)
《数据结构算法与数据结构复习.ppt》由会员分享,可在线阅读,更多相关《数据结构算法与数据结构复习.ppt(13页珍藏版)》请在淘文阁 - 分享文档赚钱的网站上搜索。
1、算法与数据结构复习n 习题习题3.33.3:如果对循环队列采用设置运算标志的方式来区分队列的满和空的状态,试给出对应的各运算实现。在队列的类定义里加入一个标志位tag。queue:queue()count=0;front=rear=0;tag=0;bool queue:empty()const if(front=rear&tag=0)return true;else return false;bool queue:full()const if(front=rear&tag=1)return true;else return false;error_code queue:append(const
2、 elementtype x)if(full()return overflow;rear=(rear+1)%maxlen;datarear=x;count+;tag=1;return success;error_code queue:serve()if(empty()return underflow;front=(front+1)%maxlen;count-;tag=0;return success;n 习题习题4.24.2:如果采用带尾指针的单循环链表作为队列的存储结构,设计算法以实现队列的各运算。q1q2qn.队头元素队尾元素rearqueue:queue()rear=new node;r
3、ear-next=rear;count=0;bool stack:empty()const return rear-next=rear;error_code queue:get_front(elementtype&x)const if(empty()return underflow;x=rear-next-next-data;return success;error_code queue:append(const elementtype x)node*s=new node;s-data=x;s-next=rear-next;rear-next=s;rear=s;count+;return su
4、ccess;error_code queue:serve()if(empty()return underflow;node*front=rear-next;node*u=front-next;front-next=u-next;delete u;count-;if(front-next=NULL)rear=front;return success;习题习题5.55.5:递增有序顺序表A、B分别表示一个集合,设计算法求解A=A-B,并分析其时间性能。dataiadataib:A当前元素可能在B中,ib+dataia=dataib:删除A当前元素,ib+;void subtraction(list
5、&A,list B)int ia,ib,x,y;ia=ib=1;while(ia=A.length()&ib=B.length()A.get_element(ia,x);B.get_element(ib,y);if(xy)ib+;else A.delete_element(ia);ib+;时间性能时间性能:O(|A|+|B|)O(|A|+|B|)习题习题2 2:假设递增有序顺序表A、B分别表示一个集合,设计算法求解C=AB,并分析其时间性能。dataiadataib:A当前元素可能在B中,ib+dataia=dataib:将该元素插入C表中 ia+,ib+,ic+void intersecti
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 数据结构 算法 复习
![提示](https://www.taowenge.com/images/bang_tan.gif)
限制150内