Write 2 classes that implement a queue with enqueue and dequeue operatons. One s
ID: 3697306 • Letter: W
Question
Write 2 classes that implement a queue with enqueue and dequeue operatons. One should be called QueueL and internally should store the data in a C# linked list. The other, QueueO, can use a different data structure of your choice. Write a console application to determine the time required to perform the push/pop or queue/dequeue operations on your stacks and queues. Make an instance of a C# stack and a C# queue. Get the time required to push 10,000,000 values onto each stack and then get the time required to pop 10,000,000 values from each stack. Repeat the process using the queue and dequeue operations with the queues. Your console app should be similar to the one we used for lab 7 with the linked lists and lists. Your submission should include hard copy of the source code of your program, the 4 classes, a printout of the times required and a short analysis of the efficiency of your data structures and the built-in C# data structure for both the stacks and queues.
Explanation / Answer
public class ListQueue { public static void main(String[] args){ Queue myQueue; Scanner sc = new Scanner(System.in); String input; int choice = 99; do{ System.out.println("================"); System.out.println("Queue Operations Menu"); System.out.println("================"); System.out.println("1,Enquene"); System.out.println("2,Dequeue"); System.out.println("3,Empty?"); System.out.println("4,Count?"); System.out.println("5,View Queue"); System.out.println("0, Quit "); System.out.println("Enter Choice:"); try{ choice = sc.nextInt(); switch(choice){ case 1: System.out.println("Please enter name: "); input = sc.next(); myQueue.enqueue(input); System.out.println(input + "is successful queued"); break; case 2: if(myQueue.isEmpty()){ } break; case 3: if(myQueue.isEmpty()){ System.out.println("Queue is empty"); }else{ System.out.println("Queue is not empty"); } break; case 4: System.out.println("Number of people is " + "the queue" + myQueue.size()); break; case 5: if(!myQueue.isEmpty()) myQueue.viewQueue(); else System.out.println("Queue is empty"); break; case 0: System.out.println("Good-bye"); break; default: System.out.println("Invalid choice"); } } catch(InputMismatchException e){ System.out.println("Please enter 1-5, 0 to quit"); sc.nextLine(); } }while(choice != 0); }
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.