版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、3-16public interface back public void append(Object obj) throws Exception; public Object delete() throw Exception; public Object getFront() throw Exception; public boolean notEmpty();public class Forback implements back static final int defauleSize = 10; int front; int rear; int count; int maxSize;
2、Object data; int tag=0; public Forback() initiate(defauleSize); public Forback(int sz) initiate(sz); private void initiate(int sz) maxSize = sz; front = rear = 0; count = 0; data = new Objectsz; public void append(Object obj) throws Exception if (count > 0 && front = rear) throw new Excep
3、tion("出错了"); datarear=obj; rear=(rear+1)%maxSize; count+; tag=1; public Object delete() throws Exception if(count=0) throw new Exception("队列已空"); Object temp=datafront; front=(front+1)%maxSize; count-; tag=0; return temp; public Object getFront() throws Exception if(count=0) thro
4、w new UnsupportedOperationException("队列已空"); return datafront; public boolean notEmpty() return count!=0; public class Text_for_16 public static void main(Stringargs) int n=10; SeQueue m=new SeQueue(n); int temp=11; try for(int i=1;i<=n;i+) m.append(i); System.out.println();System.out.p
5、rintln( "取值: "+m.getFront(); System.out.println("删除: "+m.delete(); System.out.println("所得结果为 "+temp); m.append(temp); System.out.print(m.getFront()+" "); if(m.rear=m.front&&m.tag=0) System.out.println(""); else System.out.println("所得结果为&
6、quot;); m.delete(); System.out.println("所得的结果为:"); for(int i=0;i<n;i+) System.out.print(m.delete()+" "); catch(Exception e) System.out.print(e.getMessage(); 3-17public interface back public void append(Object obj)throws Exception; public Object delete()throws Exception; public
7、 Object getFront()throws Exception; public boolean notEmpty();public class tpback implements back static final int defauleSize = 10; int front; int rear; int count; int maxSize; Object data; int tag=0; public tpbak() initiate(defauleSize); public tpback(int sz) initiate(sz); private void initiate(in
8、t sz) maxSize = sz; front = rear = 0; count = 0; data = new Objectsz; public void append(Object obj) throws Exception if (count > 0 && front = (rear+1)%maxSize) throw new Exception("队列已空"); datarear=obj; front=(rear+1)%maxSize; count+; public Object delete() throws Exception if(
9、count=0) throw new Exception("队列空"); Object temp=datafront; front=(front+1)%maxSize; count-; return temp; public Object getFront() throws Exception if(count=0) throw new UnsupportedOperationException("已满"); return datafront; public boolean notEmpty() return count!=0; public class
10、 Test_for_17 public static void main(Stringargs) int n=10; SeQueue m=new SeQueue(n); int temp=11; try for(int i=1;i<=n;i+) m.append(i); System.out.println(); System.out.println("删除: "+m.delete(); System.out.println( "取值: "+m.getFront(); System.out.println("结果为 "+temp
11、); m.append(temp); System.out.print(m.getFront()+" "); if(m.rear=m.front&&m.tag=0) System.out.println("结果为"); else System.out.println("结果为); m.delete(); System.out.println("结果为:"); for(int i=0;i<n;i+) System.out.print(m.delete()+" "); catch(Exc
12、eption e) System.out.print(e.getMessage(); 3-18public interface dps public void push(Object obj)throws Exception; public Object pop()throws Exception; public Object getTop()throws Exception; public boolean notEmpty();public class Lindps implements dps Node head; int size;public void Lindps() head=nu
13、ll; size=0; public void push(Object obj) throws Exception head=new Node(obj,head); size+; public Object pop() throws Exception if(size=0) throw new Exception("鍫嗘爤宸茬"); Object obj=head.element; head=head.next; size-; return obj; public Object getTop() throws Exception return head.element; p
14、ublic boolean notEmpty() return head!=null; public class Dot Object element; Dot next; Dot(Node nexttval) next=nexttval; Dot(Object obj,Node nexttval) element=obj; next=nexttval; public Dot getNext() return next; public void setNext(Dot nexttval) next=nexttval; public Object getElement() return elem
15、ent; public void setElement(Object obj) element=obj; public String toString() return element.toString(); public class postback public static void postExp(String ch) throws Exception tpback s = new tpback(); Object x1, x2; s.push('#'); for (int i = 0; i <ch.length(); i+) x2 = ch.charAt(i);
16、 x1 = s.getTop(); if (x2.equals('+') | x2.equals('-') | x2.equals('*') | x2.equals('/')|x2.equals('#') if (x1.equals('#') s.push(x2); else if (x2.equals('*') | x2.equals('/') && (x1.equals('+') | x1.equals('-') s
17、.push(x2); else if (x2.equals('*') | x2.equals('/') && (x1.equals('*') | x1.equals('/') System.out.print(s.pop(); s.push(x2); else if (x2.equals('+') | x2.equals('-') System.out.print(s.pop(); if(s.getTop().equals('+')|s.getTop().equals('-') System.out.print(s.pop(); s.push(x2); if(x2.equals('#') System.out.print(s.pop(); if(s.getTop().equals('+')|s.getTop().equals('-') System.out.print(s.pop(); else System.out.print(x2); public class Test_for_18 public stati
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 4s店客户经理考核制度
- 2025年暨南大学马克思主义基本原理概论期末考试模拟题及答案解析(必刷)
- 2025年屏山县招教考试备考题库带答案解析(必刷)
- 2025年青海民族大学马克思主义基本原理概论期末考试模拟题附答案解析(夺冠)
- 2025年四川文化传媒职业学院单招职业技能考试题库附答案解析
- 2025年兰州工商学院马克思主义基本原理概论期末考试模拟题含答案解析(夺冠)
- 2025年上海建桥学院马克思主义基本原理概论期末考试模拟题含答案解析(夺冠)
- 2025年浙江邮电职业技术学院单招综合素质考试题库带答案解析
- 江西数字集团本部2025年内部招聘笔试有关笔试历年难易错考点试卷带答案解析
- 2025年四川铁道职业学院马克思主义基本原理概论期末考试模拟题含答案解析(必刷)
- 高考全国乙卷物理考试卷含解析及答案
- 海尔集团预算管理实践分析
- 污水池清理作业安全应急预案方案
- 2025年中国电信招聘笔试大纲及备考指南
- 制造业自动化设备调试操作手册
- 莫兰迪工作总结计划
- 2025租房合同范本下载(可直接打印)
- 中建总进度计划编排交流汇报
- 2025年四川省成都市中考英语真题(原卷版)
- 分级护理标准2025版解读
- 英语高考核心高频688词汇
评论
0/150
提交评论