队列是设计程序中常用的一种数据结构。它类似日常生活中的排队现象,采用一种被称为“先进先出”(LIFO)的存储结构。 队列是设计程序中常用的一种数据结构。它类似日常生活中的排队现象,采用一种被称为“先进先出”(LIFO)的存储结构。
Vector类是JAVA中专门负责处理对象元素有序
Vector类是JAVA中专门负责处理对象元素有序 import java.util.*;
public class BroadCastQueue extends Vector {//向量的子类
public BroadCastQueue(){ super(); } public synchronized void enq(Object x) { super.addElement(x); } public synchronized Object deq() {
/* 队列若为空,引发EmptyQueueException异常 */ if( this.empty() ) throw new EmptyQueueException(); Object x = super.elementAt(0); super.removeElementAt(0); return x; } public synchronized Object front() {
if( this.empty() ) throw new EmptyQueueException(); return super.elementAt(0); } public boolean empty() {
return super.isEmpty(); } public synchronized void clear() {
super.removeAllElements(); } public int search(Object x) {
return super.indexOf(x); } } import java.util.*;
public class BroadCastQueue extends Vector {//向量的子类
public BroadCastQueue(){ super(); } public synchronized void enq(Object x) { super.addElement(x); } public synchronized Object deq() {
/* 队列若为空,引发EmptyQueueException异常 */ if( this.empty() ) throw new EmptyQueueException(); Object x = super.elementAt(0); super.removeElementAt(0); return x; } public synchronized Object front() {
if( this.empty() ) throw new EmptyQueueException(); return super.elementAt(0); } public boolean empty() {
return super.isEmpty(); } public synchronized void clear() {
super.removeAllElements(); } public int search(Object x) {
return super.indexOf(x); } } import java.lang.*;
public class EmptyQueueException extends RuntimeException{
public EmptyQueueException(){ } } |
|