In Java Please

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

In Java Please

Post by answerhappygod »

In Java Please
In Java Please 1
In Java Please 1 (82.6 KiB) Viewed 29 times
11 11 11 Background Description Below in the double quotes are some word strings: "All" ---1 " limitations" ---2 are ---3 self" ---4 "imposed" ---5 We are going to store and retrieve those strings in both of stack and queue structures, respectively, in certain operation sequence. In the operation sequence, the number represents storing corresponding string, and X represents a retrieval (i.e., not just looking at it with peek(), but also remove an element from the data structure). For example, the operation sequence 53X2 means doing the following operations step by step: store string 5 store string 3 retrieve a string store string 2 Assume that we start the operations at an empty data structure, then the sample sequence 53X2 in a stack structure will be push 5, push 3, pop, push 2. After the operations there will be 5 and 2 in the stack which is: "imposed" "limitations" top In queue structure, the sample sequence 53X2 will be enqueue 5, enqueue 3, dequeue, enqueue 2. After the operations there will be 2 and 3 in the queue which is: rear "limitations" are" front Task 1 Fill in the textboxes below to show what's in the data structure after each operation sequence. Use space to separate each string. Please assume the beginning data structure is always empty for each sequence. 12X34 top In stack structure: Click or tap here to enter text. front In queue structure: rear Click or tap here to enter text. 5X2X3X45 In stack structure: Click or tap here to enter text. top In queue structure: rear Click or tap here to enter text. front
2X3X4X5X In stack structure: Click or tap here to enter text. top In queue structure: front Click or tap here to enter text. rear Task 2: Write a java program that performs the operation sequence given below on stack and queue data structure respectively: 1X23X4X5 In your program write codes to do the following step by step: 1. Declare a stack 2. Perform the operation sequence in stack 3. Print the elements in stack after all the operations 4. Declare a queue 5. Perform the operation sequence in queue 6. Print the elements in queue after all the operations For the data structures, you can use either those available in the Java Collection Framework, or of your own implementation. * Bonus possible if your program allows user to enter any operation sequence, parse the sequence, and show result accordingly.
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply