Java编程:用数组实现队列的存取

Java编程:用数组实现队列的存取,在JCreator4.0中运行成功!
/**
* @(#)Queue01.java
*Java编程:用数组实现队列的存取
*
* @author kemwin
* @version 1.00 2007/12/20
*/
import java.io.*;

public class Queue01 {

static class QueueArray{
int MaxSize = 10;
int[] AQueue = new int[MaxSize];
int Front = -1;
int Rear = -1;
//----------------------
//print out the data
//----------------------
public void Print(){
int i;
System.out.print("The Queue Content;");
for(i=Front+1;i<Rear+1;i++)
System.out.print("["+AQueue[i]+"]");
System.out.println("");
}
//-----------------------
//save the queue data
//-----------------------
public void AddQueue(int Value){
int i;
if(Rear >=MaxSize)
System.out.println("The Queue is full!");
else{
Rear++;
AQueue[Rear]=Value;
}
}
//-------------------------
//call out the data
//-------------------------
public int DelQueue()
{
int Temp;
if( Front == Rear ){
System.out.println("The stack is empty!!");
return -1;
}
Front++;
Temp = AQueue[Front];

return Temp;
}

}
/**
* Creates a new instance of <code>Queue01</code>.
*/


/**
* @param args the command line arguments
*/
public static void main(String[] args)throws IOException {
// TODO code application logic here
int Select;
QueueArray Queue01 = new QueueArray();
int i;
int Value;

do{
System.out.println("1.Input a queue data");
System.out.println("2.Output a queue data");
System.out.println("3.Exit");
System.out.print("please select one=>");

//
BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
String str = br.readLine();
Select=Integer.parseInt(str);
//
switch(Select){
case 1:
System.out.print("Please input the data=>");
BufferedReader br2=new BufferedReader(new InputStreamReader(System.in));
String str2 = br2.readLine();
Value = Integer.parseInt(str2);
Queue01.AddQueue(Value);
Queue01.Print();
System.out.println("");
break;
case 2:
Value =Queue01.DelQueue();
Queue01.Print();
System.out.println("");
break;
}
}while(Select !=3);

}


}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值