Пример #1
0
  /**
   * 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;
  }
Пример #2
0
	for(int i = 0; i < 100; i++){
	    String s = "" + i;
	    s.push(s);
	    myS.push(s);
	    q.enqueue(s);
	    myQ.enqueue(s);
	}
Пример #3
0
 public static void main(String[] args) {
   Solution34 sol34 = new Solution34();
   int[] values = new int[] {11, 34, 2, 6, 23, 5, 10};
   System.out.print("Create the queue: ");
   MyQueue queue = sol34.new MyQueue(values);
   sol34.printOutQueue(values);
   System.out.print("Remove three elements: ");
   for (int i = 0; i < 3; i++) {
     System.out.print(queue.remove() + "  ");
   }
   System.out.println();
   System.out.print("Peek the next element: ");
   System.out.print(queue.peek());
   System.out.println();
   System.out.print("Add one element 0 and print out all current queue: ");
   queue.add(0);
   while (!queue.isEmpty()) {
     System.out.print(queue.remove() + "  ");
   }
 }