Você está na página 1de 4

import import import import import public

java.io.*; java.util.InputMismatchException; java.io.IOException; java.io.InputStreamReader; java.util.Scanner; class my_cir_arr_deq { /** Scanner to read from input console. */ static Scanner scIn; // Constructor /** Default constructor. */ public my_cir_arr_deq() { scIn = new Scanner(System.in); }

//main class of library public static void main(String args[])throws IOException {

my_cir_arr_deq m=new my_cir_arr_deq(); cirardeq ob_deq=new cirardeq(10);//creating an object of library array list for book System.out.println("Enter your choice"); BufferedReader br1=new BufferedReader(new InputStreamReader(Syst em.in)); String choice = br1.readLine(); int ch =Integer.parseInt(choice); String[] commands = { "offer first", "offer last", "add in the front", "add at the last", "Remove element from front", "Remove element from last", "poll element at the front", "poll element at the last", "peek element from front", "peek element from last", "get element from front", "get element from last", "display", "Exit"}; do { for (int i = 0; i < commands.length; i++) { System.out.println("Select " + i + ": " + commands[i]); } try { ch = scIn.nextInt(); // Read the next choice.

scIn.nextLine(); // Skip trailing newline. switch (ch) { case 0: System.out.println("Enter the element which yo u want to add"); BufferedReader br=new BufferedReader(new InputS treamReader(System.in)); String str = br.readLine(); int i =Integer.parseInt(str); ob_deq.offerFirst(i); System.out.println("Element has been added"); break; case 1: System.out.println("Enter the element which you want to add"); BufferedReader br2=new BufferedReader(new Input StreamReader(System.in)); String str2 = br2.readLine(); int j =Integer.parseInt(str2); ob_deq.offerLast(j); System.out.println("Element has been added"); break; case 2: System.out.println("Enter the element which yo u want to add"); BufferedReader br3=new BufferedReader(n ew InputStreamReader(System.in)); String str3 = br3.readLine(); int k =Integer.parseInt(str3); ob_deq.addFirst(k); System.out.println("Element has been ad ded"); break; case 3: System.out.println("Enter the element which yo u want to add"); BufferedReader br4=new BufferedReader(n ew InputStreamReader(System.in)); String str4 = br4.readLine(); int l =Integer.parseInt(str4); ob_deq.addLast(l); System.out.println("Element has been ad dedd"); break; case 4: System.out.println(ob_deq.removeFirst()); System.out.println("Element has been re moved"); break; case 5: ob_deq.removeLast(); System.out.println("Element has been re moved");

break; case 6: ob_deq.pollFirst(); System.out.println("Element has been re moved"); break; case 7: ob_deq.pollLast(); System.out.println("Element has been re moved"); break; case 8: System.out.println(ob_deq.peekFirst()); break; case 9: System.out.println(ob_deq.peekLast()); break; case 10: System.out.println(ob_deq.getFirst()); break; case 11: System.out.println(ob_deq.getLast()); break; case 12: ob_deq.display(); break; default: System.out.println("*** Invalid choice " + choice + " - try again!"); } } catch (InputMismatchException ex) { System.out.println("*** Incorrect data entry - " + "enter an integer between 0 and " + (commands.length-1)); scIn.nextLine(); // Discard bad input. ch = -1; } } while (ch != commands.length - 1); System.exit(0); }

Você também pode gostar