Untitled
unknown
plain_text
2 years ago
2.4 kB
5
Indexable
public class QueueArray<T> { static int MAX = 1000; T[] queue = (T[]) new Object[MAX]; int front; int rear; public QueueArray() { front = 0; rear = 0; } public boolean isEmpty() { return front == rear; } public void enQueue(T item) { queue[rear] = item; rear = (rear + 1) % MAX; } public T deQueue() { T tmpT; if (isEmpty()) { return null; } else { tmpT = queue[front]; front = (front + 1) % MAX; return tmpT; } } // public void sortQueue() // { // QueueArray<PointQ> queueArray = new QueueArray<PointQ>(); // for(int i = front; i < rear; i++) // { // for(int j = front+1; j<rear-1;j++) // if(queueArray[front].time) // } // } // public static void main(String[] args) { // QueueArray<PointQ> queueArray = new QueueArray<PointQ>(); // PointQ pointQ1252 = new PointQ(8, 7, 9); // PointQ pointQ3 = new PointQ(10, 11, 12); // queueArray.enQueue(pointQ1252); // queueArray.enQueue(pointQ3); // while (!queueArray.isEmpty()) { // System.out.println(queueArray.deQueue().x); // // System.out.println(queueArray.deQueue().y); // // System.out.println(queueArray.deQueue().time); // } // } } class PointQ { int x; int y; int time; public PointQ() { } public PointQ(int x, int y, int time) { this.x = x; this.y = y; this.time = time; } } public class StackArray<T> { T[] stack = (T[]) new Object[1000]; int top; public StackArray() { this.top = -1; } public void push(T item) { top++; stack[top] = item; } public T pop() { if (isEmpty()) { return null; } else { return stack[top--]; } } public boolean isEmpty() { return top == -1; } public static void main(String[] args) { Point point1 = new Point(20, 30); Point point2 = new Point(40, 70); StackArray<Point> stackArray = new StackArray<Point>(); stackArray.push(point1); stackArray.push(point2); // stackArray.push(3); while (!stackArray.isEmpty()) System.out.println( stackArray.pop().x); } } class Point { int x; int y; public Point(int x, int y) { this.x = x; this.y = y; } } // StackArray<Point> stack = new StackArray<Hugo.Point>(); // Point tmpPoint = stack.pop(); // tmpPoint.x // // Xqueue.push(x) // Point p = new Point(x, y); // stack.push(p);
Editor is loading...