package cpsc2150.MyDeque;

import java.util.Scanner;

/**
 * Class that contains a main method for use with IDeque and classes that implement IDeque.
 */
public class DequeApp {

    /**
     * Main method for DequeApp that asks a user which type of deque
     * they'd like to use and adds some integers to the deque.
     *
     * @param args Command-line arguments
     *
     * @post
     *      [ a list of integers added to a deque will be printed ]
     */
    public static void main(String[] args) {

        IDeque q;

        // Prompt for input
        System.out.println("Enter 1 for array implementation or 2 for List implementation");

        Scanner input = new Scanner(System.in);
        // Take in input
        int choice = input.nextInt();

        // Verify that user entered 1 or 2
        while (choice != 1 && choice != 2) {

            // Prompt for input again
            System.out.println("Enter 1 for array implementation or 2 for List implementation");
            // Take in input again
            choice = input.nextInt();

        }

        // If choice is 1, initialize ArrayDeque
        if (choice == 1) {

            q = new ArrayDeque();

          // If choice is 2, initialize ListDeque
        } else {

            q = new ListDeque();

        }

        Integer x = 3;
        q.enqueue(x);
        x = -8;
        q.enqueue(x);
        x = 15;
        q.enqueue(x);
        x = 0;
        q.enqueue(x);
        x = -4;
        q.enqueue(x);

        System.out.print("<");
        // Loop through indexes in q
        for (int i = 0; i < q.length(); i++) {

            // Call dequeue function to store next value
            int removed = q.dequeue();

            // Check if i is equal to length of q
            if (i != q.length()) {

                // Print value with comma and space
                System.out.print(removed + ", ");

            } else {

                // Print value
                System.out.print(removed);

            }

            // Add removed value back to deque in order
            q.enqueue(removed);

        }

        System.out.println(">");

    }

}
