|
隊列是設計程序中常用的一種數據結構。它類似日常生活中的排隊現象,采用一種被稱為“先進先出”(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() {
/* 隊列若為空,引發(fā)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() {
/* 隊列若為空,引發(fā)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(){ } } |
|
|