I need help writing a program using a character Queue. I am using the Queue to determine if the two sequences of characters are the same as each other. Also I have to implement my character Queue as a linked list (using Nodes). Can anyone out there help me write the "Main" part.

Here is my classes

class Queue
{
Node *front;
Node *rear:
}
public:
Queue();
~Queue();
void Make Empty();
void Enqueue(char);
void Dequeue(char&);
bool IsEmpty(); const
bool IsFull(); const
};

struct Node
{
char letter;
Node *nextp;
}

>Can anyone out there help me write the "Main" part.

#include <iostream>
#include <queue>

using namespace std;

int main()
{
  queue<char> q;
  char ch;
  bool match = true;

  cout<<"Enter a message: ";
  while ( cin.get ( ch ) && ch != '\n' )
    q.push ( ch );

  cout<<"Enter another message: ";
  while ( cin.get ( ch ) && ch != '\n' ) {
    if ( q.empty() || q.front() != ch )
      match = false;

    q.pop();
  }

  if ( match )
    cout<<"The two messages match"<<endl;
  else
    cout<<"The two messages do not match"<<endl;
}

Replace the standard queue adaptor with your queue and that's it!

>Can anyone out there help me write the "Main" part.

#include <iostream>
#include <queue>

using namespace std;

int main()
{
  queue<char> q;
  char ch;
  bool match = true;

  cout<<"Enter a message: ";
  while ( cin.get ( ch ) && ch != '\n' )
    q.push ( ch );

  cout<<"Enter another message: ";
  while ( cin.get ( ch ) && ch != '\n' ) {
    if ( q.empty() || q.front() != ch )
      match = false;

    q.pop();
  }

  if ( match )
    cout<<"The two messages match"<<endl;
  else
    cout<<"The two messages do not match"<<endl;
}

Replace the standard queue adaptor with your queue and that's it!

What do you mean replace the standard queue adaptor with my queue?
I am totally lost on this program so, please forgive me If I sound dum.

Now where you said "q.push(ch)" will I push the queue or will I Enqueue.

What I have to do is Enter two strings separated by only by a : (colon)
So I dont need to enter a message and then enter another message.
I just need to be able to enter it this way: hello:olleh and the program is
suppose to tell if they are the mirror image. Also, I'm having to use Nodes in this program.

Thank you for helping me

>What do you mean replace the standard queue adaptor with my queue?
push and pop are equivalent to enqueue and dequeue. Any other changes to use your queue instead of the standard C++ queue are painfully obvious if you give it a shot. Play around with the code and you'll figure it out. What more did you expect me to do? I gave you the answer.

This article has been dead for over six months. Start a new discussion instead.