欢迎使用CSDN-markdown编辑器

来源:互联网 发布:noesis.javascript 编辑:程序博客网 时间:2024/06/01 08:35

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

原创粉丝点击