?? queue.java
字號(hào):
package com.lzw;
/**
“先進(jìn)先出”(LIFO)的存儲(chǔ)結(jié)構(gòu)。數(shù)據(jù)元素只能從隊(duì)尾進(jìn)入,從隊(duì)首取出。在隊(duì)列中,
數(shù)據(jù)元素可以任意增減,但數(shù)據(jù)元素的次序不會(huì)改變。每當(dāng)有數(shù)據(jù)元素從隊(duì)列中被取出,
后面的數(shù)據(jù)元素依次向前移動(dòng)一位。所以,任何時(shí)候從隊(duì)列中讀到的都是隊(duì)首的數(shù)據(jù)。
根據(jù)這些特點(diǎn),對(duì)隊(duì)列定義了以下六種操作:
push(x) 向隊(duì)列插入一個(gè)值為x的元素;
pop() 從隊(duì)列中取出一個(gè)元素;
front() 從隊(duì)列中讀一個(gè)元素,但隊(duì)列保持不變;
empty() 判斷隊(duì)列是否為空,空則返回真;
clear() 清空隊(duì)列;
search(x) 查找距隊(duì)首最近的元素的位置,若不存在,返回-1
*/
public class Queue extends java.util.Vector {
public class EmptyQueueException extends java.lang.RuntimeException {
public EmptyQueueException() {
super();
}
}
public Queue() {
super();
}
public synchronized void push(Object x) {
super.addElement(x);
}
public synchronized Object pop() {
/* 隊(duì)列若為空,引發(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 this.isEmpty();
}
public synchronized void clear() {
super.removeAllElements();
}
public int search(Object x) {
return super.indexOf(x);
}
}
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號(hào)
Ctrl + =
減小字號(hào)
Ctrl + -