实验报告三栈和队列
一、 实验目的:
(1) 掌握栈的根本操作的实现方法。
(2) 利用栈先进后出的特点,解决一些实际问题。
(3) 掌握链式队列与循环队列的根本操作算法。
(4) 应用队列先进先出的特点,解决一些实际问题。
二、 实验容:
1、使用一个栈,将一个十进制转换成二进制。
粘贴源程序:
package Q1;
publicclass SeqStack {
publicintelement[];
publicinttop;
publicstatic SeqStack p;
public SeqStack(intsize){
this.element=newint[size];
this.top=-1;
}
publicvoid push(int x){
this.top++;
this.element[this.top]=x;
}
publicint pop(){
returnthis.top==-1 ? -1: (int)this.element[this.top--];
}
publicint get(){
returnthis.top==-1 ? -1: (int)this.element[this.top];
}
publicstaticvoid disp(SeqStack p){
int t = -2;
while(t!=-1){
t=p.pop();
if(t!=-1)
System.out.printf("%d",t);
}
}
publicstaticvoid fun(int x){
int t;
while(x!=1){
t=x%2;
x=x/2;
p.push(t);
}
if(x==1)
1 / 6