您的位置:首页 > 其它

欢迎使用CSDN-markdown编辑器

2017-10-15 18:57 211 查看
package Text;

public class Stack {

private Object[] objects;

private int head;

private int size;

public Stack(int size) {
objects = new Object[size];
this.head = 0;
this.size = 0;
}

public void push(Object object) throws Exception {
if (this.size == objects.length)
throw new Exception("this stack is full");
objects[head++] = object;
size++;
}

public Object pop() throws Exception {
if (size == 0)
throw new Exception("this stack is empty");
size--;

return objects[--head];
}


}

package Text;

public class Queue {

private Object[] objects;

private int size;

private int head;

private int end;

public Queue(int size) {
this.objects = new Object[size];
this.head = 0;
this.end = 0;
this.size = 0;
}

public void push(Object object) throws Exception {
if (this.size > objects.length)
throw new Exception("Queue is full!");
objects[end++] = object;
size++;
}

public Object pop() throws Exception {
if (this.size == 0)


// return null;

throw new Exception(“Queue is empty!”);

if (head == objects.length)

this.head = 0;

size–;

return objects[head++];

}

public Object peek() throws Exception {
if (this.size == 0)
throw new Exception("Queue is empty!");
return objects[head];
}

public boolean isEmpty() {
return size == 0;
}

public boolean isFull() {
return size == objects.length;
}

public int getSize() {
return size;
}


}

冒泡排序

package sort;

public class Bubble1 {

public static int[] sort(int[] a){

for(int i=0;i
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: