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

📄 queue.java

📁 “JSP数据库项目案例导航”一书从第一章到第十一章各章实例的源程序文件以及数据库文件。 注意: 1. 本书中的案例提供的数据库环境不同
💻 JAVA
字号:
package com.util;
import java.lang.*;

public class Queue //动态链表队列类
{
	class QueueNode //链表节点类
	{
		private Object tData;
		private QueueNode next;
		public QueueNode(Object tData,QueueNode next)
		{this.tData=tData;this.next=next;};
	};

	private QueueNode front = null;
	private QueueNode rear = null;
	private int count = 0 ;

	public Queue(){};
	public boolean IsEmpty()
	{return (front==null);}

	public void EnQueue(Object tItem) //进队
	{
		count++;
		if(front==null)
		{
			rear = new QueueNode(tItem,null);
			front = rear;
			return;
		}

		QueueNode tp = rear;
		rear = new QueueNode(tItem,null);
		tp.next = rear;
		return;
	}

	public Object DeQueue() //出队
	{
		if(front==null)
			return null;
		
		count--;
		QueueNode tp = front;
		front = front.next;
		tp.next = null;
		if(front==null)
			rear = null;
		return tp.tData;
	}

	public Object GetFront() //取出队头元素
	{
		if(front==null)
			return null;
		return front.tData;
	}

	public void EmptyQueue() //清空队
	{
		count = 0 ;
		if(front==null)
			return;
		QueueNode tp = front;
		while(front!=null)
		{
			tp.next = null;
			front = front.next;
			tp = front;
		}
		rear = null;
	}

	public int getCount ( )
	{
		return count ;
	}

	public static void main(String args[])
	{
		Queue q = new Queue();
		q.EnQueue("abd");
		q.EnQueue("dtagda");
		q.EnQueue("4523");
		//q.EmptyQueue();
		com.parser.Configuration.QUEUE.EnQueue("ggg");
		com.parser.Configuration.QUEUE.EnQueue("ttt");
System.out.println(com.parser.Configuration.QUEUE.getCount());
		while ( !q.IsEmpty ( ) )
		{
			System.out.println ( "\r\n    [" + q.DeQueue ( ) + "]" ) ;
		}
	}
}

⌨️ 快捷键说明

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