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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37

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


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#include <iostream>
#include <fstream>
#include <string>
#include <stack>
#include <queue>

using namespace std;

//interleave the queue
void interleaveQ(queue<int>& queueone)
{

     if (queueone.size() % 2 != 0)
          cout << "even number of integers" << endl;

     //stack initialization
     stack<int> 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<int> 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.
Registered users can post here. Sign in or register to post.