C++

Farabi T.

asked • 06/17/20

data structure program of c++

Based on the header file given below;

Write the code for main( ) function to decode the secret message as given in the array of characters below by using the concept of Stack Linked List. You are required to insert the decoded characters into two (2) stack alternatively; the first character is decoded and push into the first stack, the second character is decoded and push into the second stack, the third character is decoded and push into the first stack again, the fourth character is decoded and push into the second stack again and alternately until the end of the array.

 

You have to use the given array and decode each character based on the following:-

              char data [ 8 ] = {'M', 'G', 'G', 'E', 'G', 'P', 'R', 'Q'};

 

To decode the secret message in the array, you are required to replace the characters based on the secret key. The key for the first stack is -2 and the key for the second stack is -4. This means, before you push the first character into the first stack, you must replace it with the character of two (2) letters backward while the second character for the second stack must be replaced with the character of four (4) letters backward. This is done for each character alternatively for the given array. For example, letter 'M' will be replaced by letter 'K' for the first stack and letter 'G' will be replaced with letter 'C' for second stack. You must use coding to do the replacement of the characters.

 

Your code must also display data from both stack. As the stack will store data by using the concept of First In Last Out, all data in the stack will be in reverse after printing. You may use another one or two stack more or any other way to rearrange the output of the first and second stack so that the printed values will be in correct order.

 

You may use or call any of the following functions to write the code for main( ) function:-

·        Push( )

·        Pop( )

·        Empty( )

·        TopStack( )

 

Output Example:

    K E E P C A L M                                                 

 

//StackLL.h

#ifndef STACKLL_H

#define STACKLL_H

template <class MyData>

struct Nod

{

      MyData data;

      Nod <MyData> *next;

};

 template <class MyData>

class StackLL

{

private:

      int count;

      Nod <MyData> *top;

public:

      StackLL();

      void Push(MyData);

      void Pop();

      bool Empty();

      MyData TopStack();

};

#endif;

1 Expert Answer

By:

Patrick B. answered • 06/18/20

Tutor
4.7 (31)

Math and computer tutor/teacher

Still looking for help? Get the right answer, fast.

Ask a question for free

Get a free answer to a quick problem.
Most questions answered within 4 hours.

OR

Find an Online Tutor Now

Choose an expert and meet online. No packages or subscriptions, pay only for the time you need.