Question
Algorithm to Interleave the first half of the queue with second half My Encoding Algorithm Following are the steps used to encode a list of
Algorithm to Interleave the first half of the queue with second half
My Encoding Algorithm
Following are the steps used to encode a list of words: 1. Push the first half elements of queue to stack. 2. Enqueue back the stack elements. 3. Dequeue the first half elements of the queue and enqueue them back. 4. Again push the first half elements into the stack. 5. Interleave the elements of queue and stack.
I have an encode data file that I need decoded. The algorithm I used to encode the data is shown above. Your problem is to decode the encoded data. The input will be a txt file of words which consists of a list of words that have been encoded as described above. Write a program to input the txt file and print out the decoded results.
Restrictions: You must use aggregate Stack and Queue class. To solve this problem, you can have ONE Queue and ONE Stack and only one of each. The input data will be loaded into a Queue to start with and from the Queue start your algorithm to decode the text. (Decoding as you read in your data will not be acceptable.)
loop cin >> str; yourqueue.enqueue(str); endloop
The Text File: The CS input 372 will Program be Assignment wordlist.txt Queue which Program consists Interleave of the a first list half of of words the that queue have with been second encoded half as My described Encoding above. Algorithm Restrictions: Following You are must the use steps aggregate used Stack to and encode Queue a class. list To of solve words: this 1. problem, Push you the can first have half ONE elements Queue of and queue ONE to Stack stack. and 2. only Enqueue one back of the each. stack The elements. input 3. data Dequeue will the be first loaded half into elements a of Queue the to queue start and with enqueue and them from back. the 4. Queue Again start push your the algorithm first to half decode elements the into text. the (Decoding stack. as 5. you Interleave read the in elements your of data queue will and not stack. be Your acceptable.) problem loop is cin to >> decode str; the yourqueue.enqueue(str); encoded endloop data.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started