@Override public void run() { while (threadRunFlag) { if (queue.isEmpty()) { System.out.println("wait add new Data to upload thread!"); synchronized (this) { try { wait(); } catch (InterruptedException e) { e.printStackTrace(); } } } else { Entity entity = (Entity) queue.remove(); System.out.println("current upload is:" + entity.toString()); System.out.println("list size i s :" + queue.size()); try { Thread.sleep(300); } catch (InterruptedException e) { e.printStackTrace(); } } } }
/** * return a COPY of solution. This should be : [x1,y1,x2,y2,x3,y3...] the coordinates of the * solution from start to end. Precondition : one of the solveXXX methods has already been called * (solveBFS OR solveDFS OR solveAStar) (otherwise an empty array is returned) Postcondition: the * correct solution is in the returned array */ public int[] solutionCoordinates() { MyQueue<Integer> listOfInts = new MyQueue<Integer>(); Node current = placesToGo.next(); while (current != null) { listOfInts.enqueue(current.getValue()[0]); listOfInts.enqueue(current.getValue()[1]); current = current.getPrev(); } solution = new int[listOfInts.size()]; for (int i = 0; i < solution.length; i++) { solution[i] = listOfInts.dequeue(); } return solution; }
public static void main(String[] args) { MyQueue<Integer> my_queue = new MyQueue<Integer>(); // Let's test our code against a "real" queue Queue<Integer> test_queue = new LinkedList<Integer>(); for (int i = 0; i < 100; i++) { int choice = AssortedMethods.randomIntInRange(0, 10); if (choice <= 5) { // enqueue int element = AssortedMethods.randomIntInRange(1, 10); test_queue.add(element); my_queue.add(element); System.out.println("Enqueued " + element); } else if (test_queue.size() > 0) { int top1 = test_queue.remove(); int top2 = my_queue.remove(); if (top1 != top2) { // Check for error System.out.println("******* FAILURE - DIFFERENT TOPS: " + top1 + ", " + top2); } System.out.println("Dequeued " + top1); } if (test_queue.size() == my_queue.size()) { if (test_queue.size() > 0 && test_queue.peek() != my_queue.peek()) { System.out.println( "******* FAILURE - DIFFERENT TOPS: " + test_queue.peek() + ", " + my_queue.peek() + " ******"); } } else { System.out.println("******* FAILURE - DIFFERENT SIZES ******"); } } }