sequencequeue.java

来自「1. 定义链栈」· Java 代码 · 共 57 行

JAVA
57
字号

public  class SequenceQueue implements Queue
 {
 	Object Entry[];
 	int size;
 	int maxSize;
 	static final int MAX = 20;
 	
 	public SequenceQueue()
 	{
 		Entry = new Object[MAX];
 		size = 0;
 		maxSize = MAX;
 	}
 	
 	public SequenceQueue(int s)
 	{
 		Entry = new Object[s];
 		size = 0;
 		maxSize = s; 		
 	}
 	
 	public void enqueue (Object element) //入队
 	{
 		if(size < maxSize)
 		{
 			Entry[size] = element;
 			size++;
 		}
 		else
 			System.out.println("Queue is full,sorry! ");
 	}
 	
	public Object dequeue() throws EmptyQueueException//出队
	{
		Object result = Entry[0];
		if(size > 0)
		{
		
			for(int index = 0; index < size-1; index++)
			{
				Entry[index] = Entry[index+1];			
			}
			size--;
		}
		else
			throw new EmptyQueueException();
		return result;
	}
	
	public void display()
	{
		for(int index = 0; index < size; index++)
			System.out.print("  "+Entry[index]);
			System.out.print("\n");
	}
 }

⌨️ 快捷键说明

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