⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 queue.java

📁 软件工程实践课程的答案哦
💻 JAVA
字号:
class Queue
{
	static int size;
	static ColorSet[] queue;
	static int head;
	static int rear;
	Queue()
	{
		size = 200;
		queue = new ColorSet[size];
		head = 0;
		rear = 0;
	}
    
    public static synchronized boolean isFull()
    {
    	if((rear+1)%size==head)
    	   return true;
    	      else return false;
    }
    
    public static synchronized boolean isEmpty()
    {
           if((head+1)%size==rear || (head==0&&rear==0))
    	   return true;
    	      else return false;
    }
    
    /**
	 * put a new SingleColorSet object into the queue
	 * @i the object to put into the queue*/
	public static synchronized void enQueue(ColorSet i)
	{
		queue[rear] = i; 
	  	rear = (rear+1)%size;
	}
	/**
	 * delete SingleColorSet object from the queue
	 * @return the first object of the queue*/
	public static synchronized ColorSet deQueue()
	{
		ColorSet temp = queue[head];
		head = (head+1)%size;
		return temp;
	}

	/**
	 * @return the colorSet after the current*/
	public static ColorSet getNext()
	{
	//	System.out.println("Next BarQueue:"+queue[(head+1)%size].getColor0()+","+queue[(head+1)%size].getColor1()+","+queue[(head+1)%size].getColor2()+"," );
		ColorSet temp = queue[head];
		return temp;
	}
	/**
	 * @return length of the queue*/	
	public static int getQueLen()
	{
		return (rear+size-head)%size;
	}
	
/*	public static void main(String[] args)
	{
		Queue queue = new Queue();
		
		queue.enQueue(1);
		queue.enQueue(2);
		//System.out.println((queue.rear-queue.head+queue.size)%queue.size);
		
		
		//System.out.println(queue.deQueue());
		//System.out.println(queue.deQueue());
		System.out.println(queue.getQueLen());
	}
	*/

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -