예제 #1
0
 /**
  * Returns an array of movies in the same order they they are in the queue but shares no data with
  * the actual queue.
  *
  * @pre
  * @post the array of movies will be returned in the order fo the queue
  * @return the array of movies
  */
 public Movie[] displayMoviesAtHome() {
   @SuppressWarnings("deprecation")
   MyQueue<Movie> cloneOfP = new MyQueue<Movie>(atHomeQueue);
   Movie[] movieList = new Movie[cloneOfP.getSize()];
   int i = 0;
   while (!cloneOfP.isEmpty()) {
     movieList[i] = cloneOfP.dequeue();
     i++;
   }
   return movieList;
 }
예제 #2
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;
  }
예제 #3
0
 /**
  * Dequeues from the atHome queue in FIFO order and returns the movie.
  *
  * @return the movie dequeued
  */
 public Movie returnMovie() {
   return atHomeQueue.dequeue();
 }
예제 #4
0
 public T next() {
   return frontier.dequeue();
 }