### Interleave help I have a program thats suppose to take an infile message and decipher it. I'm unsure how to make this work with the current setup that I have.

SPEC Sheet
 ``12345678910111213141516171819202122232425262728293031323334353637`` `````` CS 372 Program Assignment Queue and Stack Program 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. Interleave the first half of the queue with second half (ie encode) Given a queue of integers of even length, rearrange the elements by interleaving the first half of the queue with the second half of the queue. The data for this problem, fill the queue with the values 1 to 30. The algorithm given above. Only a stack (one stack) a queue (one queue) can be used as an auxiliary space. Examples: Input : 1 2 3 4 Output : 1 3 2 4 Input : 11 12 13 14 15 16 17 18 19 20 Output : 11 16 12 17 13 18 14 19 15 20 Number TWO (You are to decode the input) I have an encoded data file that I need decode using the above algorithm. 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. Input a string and enqueue to your string queue to start with. 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.) This is an exercise in Stacks, Queues and aggregate classes. loop cin >> str; yourqueue.enqueue(str); endloop ``````

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596`` ``````#include #include #include #include #include using namespace std; //interleave the queue void interleaveQ(queue& queueone) { if (queueone.size() % 2 != 0) cout << "even number of integers" << endl; //stack initialization stack stk1; int halfofit = queueone.size() / 2; //push the first half for (int i = 0; i < halfofit; i++) { stk1.push(queueone.front()); queueone.pop(); } //enqueue while (!stk1.empty()) { queueone.push(stk1.top()); stk1.pop(); } //dequeue first half then enqueue again for (int i = 0; i < halfofit; i++) { queueone.push(queueone.front()); queueone.pop(); } //push first half again for (int i = 0; i < halfofit; i++) { stk1.push(queueone.front()); queueone.pop(); } while (!stk1.empty()) { queueone.push(stk1.top()); stk1.pop(); queueone.push(queueone.front()); queueone.pop(); } } int main() { queue queueone; queueone.push(1); queueone.push(2); queueone.push(3); queueone.push(4); queueone.push(5); queueone.push(6); queueone.push(7); queueone.push(8); queueone.push(9); queueone.push(10); queueone.push(11); queueone.push(12); queueone.push(13); queueone.push(14); queueone.push(15); queueone.push(16); queueone.push(17); queueone.push(18); queueone.push(19); queueone.push(20); queueone.push(21); queueone.push(22); queueone.push(23); queueone.push(24); queueone.push(25); queueone.push(26); queueone.push(27); queueone.push(28); queueone.push(29); queueone.push(30); interleaveQ(queueone); cout << "Encoded Numbers 1-30:" << endl; int length = queueone.size(); for (int i = 0; i < length; i++) { cout << queueone.front() << " "; queueone.pop(); } return 0; } ``````
Last edited on Infile data:

endloop CS yourqueue.enqueue(str); 372 str; Program >>
Assignment cin Queue loop Program acceptable.) Interleave be the not first will half data of your the in queue read with you second as half (Decoding My text.
Encoding the Algorithm decode Following to are algorithm the your steps start used Queue to the encode from a and list with of start words:
to 1. Queue Push a the into first loaded half be elements will of data queue input to The stack. each.
2. of Enqueue one back only the and stack Stack elements. ONE
3. and Dequeue Queue the ONE first have half can elements you of problem, the this queue solve and To enqueue class. them Queue back. and
4. Stack Again aggregate push use the must first You half Restrictions: elements above. into described the as stack. encoded
5. been Interleave have the that elements words of of queue list and a stack. of Your consists problem which is ‘wordlist.txt’ to be decode will the input encoded The data.