实验三 栈和队列.docx

上传人:小飞机 文档编号:3436185 上传时间:2023-03-13 格式:DOCX 页数:4 大小:37.16KB
返回 下载 相关 举报
实验三 栈和队列.docx_第1页
第1页 / 共4页
实验三 栈和队列.docx_第2页
第2页 / 共4页
实验三 栈和队列.docx_第3页
第3页 / 共4页
实验三 栈和队列.docx_第4页
第4页 / 共4页
亲,该文档总共4页,全部预览完了,如果喜欢就下载吧!
资源描述

《实验三 栈和队列.docx》由会员分享,可在线阅读,更多相关《实验三 栈和队列.docx(4页珍藏版)》请在三一办公上搜索。

1、实验三 栈和队列实验报告三 栈和队列 一、 实验目的: 掌握栈的基本操作的实现方法。 利用栈先进后出的特点,解决一些实际问题。 掌握链式队列及循环队列的基本操作算法。 应用队列先进先出的特点,解决一些实际问题。 二、 实验内容: 1、 使用一个栈,将一个十进制转换成二进制。 粘贴源程序: package Q1; public class SeqStack public int element; public int top; public static SeqStack p; public SeqStack(int size) public void push(int x) public in

2、t pop public int get public static void disp(SeqStack p) public static void fun(int x) int t; while(x!=1) if(x=1) t=x%2; x=x/2; p.push(t); int t = -2; while(t!=-1) t=p.pop; if(t!=-1) System.out.printf(%d,t); return this.top=-1 ? -1: (int)this.elementthis.top; return this.top=-1 ? -1: (int)this.eleme

3、ntthis.top-; this.top+; this.elementthis.top=x; this.element=new intsize; this.top=-1; p.push(x); public static void main(String args) p=new SeqStack(13); fun(99); disp(p); 粘贴测试数据及运行结果: 2、回文是指正读反读均相同的字符序列,如“acdca”、“dceecd”均是回文,但“book”不是回文。利用1中的基本算法,试写一个算法判定给定的字符串是否为回文。 粘贴源程序: package Q2; public clas

4、s SeqStack public int element; public int top; public static SeqStack p; public SeqStack(int size) public void push(int x) public int pop public int get public static void input(String str) int i=0; int t=str.length; if(t%2=0) for(i=0;it/2;i+) p.push(str.charAt(i); return this.top=-1 ? -1: (int)this

5、.elementthis.top; return this.top=-1 ? -1: (int)this.elementthis.top-; this.top+; this.elementthis.top=x; this.element=new intsize; this.top=-1; else for(i=0;i=t/2;i+) p.push(str.charAt(i); public static boolean compare(String str,SeqStack p) public static void main(String args) boolean flag; p=new

6、SeqStack(100); String str =new String(acbca); p.input(str); flag=pare(str, p); if(flag=true) System.out.println(yes); else System.out.println(No); boolean flag = true; char t; int length=str.length; if(length%2=0) return flag; for(int i=0;ilength/2;i+) for(int i=0;ilength/2+1;i+) t=str.charAt(length/2+i); if(t!=p.pop) flag=false;break; t=str.charAt(length/2+i); if(t!=p.pop) flag=false;break; else 粘贴测试数据及运行结果: 3、 使用3个队列分别保留手机上最近10个“未接来电”、“已接来电”、“已拨电话”。

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 生活休闲 > 在线阅读


备案号:宁ICP备20000045号-2

经营许可证:宁B2-20210002

宁公网安备 64010402000987号