📄 sqqueue.java
字号:
package exercise0;
//定义队列
public class SqQueue {
public final int MAXSIZE =65535;
int front = 0;
int rear = 0;
OneState[] array;
public SqQueue() {
array = new OneState[MAXSIZE];
}
//入队
public boolean EnQueue(OneState e) {
if ((rear + 1) % MAXSIZE == front) {
System.out.println("the Queue has full;");
return false;
}
array[rear] = e;
rear = (rear + 1) % MAXSIZE;
return true;
}
//出队
public OneState DeQueue() {
if (front == rear) {
System.out.println(" the Queue is Empty;");
return null;
}
OneState e = array[front];
front = (front + 1) % MAXSIZE;
return e;
}
//判空
public boolean IsEmpty() {
if (rear == front)
return true;
return false;
}
//求长
public int QueueLength() {
return (rear - front + MAXSIZE) % MAXSIZE;
}
public void DestoryQueue() {
rear = front;
}
//排序
public void SelectSort() {
OneState[] mid = new OneState[this.QueueLength()];
int i = 0, m = 0;
while (!IsEmpty()) {
mid[i++] = DeQueue();
}
OneState z = new OneState();
for (int j = 0; j < i - 1; j++)
for (int k = j + 1; k <= i - 1; k++) {
z = mid[j];
if (mid[k].getEstimate() > z.getEstimate()) {
z = mid[k];
m = k;
}
mid[m] = mid[j];
mid[j] = z;
}
while (i != 0) {
EnQueue(mid[--i]);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -