Question: Singly Linked Queue Class, C++ Guestion: Implement a singly-linked queue class using nodes and pointers. The queue object should have three data members (1) a

Singly Linked Queue Class, C++

Guestion: Implement a singly-linked queue class using nodes and pointers. The queue object should have three data members (1) a pointer to head node (2) a pointer to the tail node, and (3) the current size of the queue (its number of elements).

Your queue objects should look like this: C++

Singly Linked Queue Class, C++ Guestion: Implement a singly-linked queue class using

The header file (Queue.h) for your queue class is given below. Make sure to implement the Big-three (copy constructor, overloaded assignment operator and destructor).

#ifndef QUEUE_H

#define QUEUE_H

#include

using namespace std;

struct Node

{

char data;

Node * next;

Node(char d = 0, Node * nptr = 0)

:data(d), next(nptr)

{}

};

class Queue

{

public:

Queue();

//copy constructor

Queue(const Queue & copy);

//destructor

~Queue();

//Overloaded assignment operator

const Queue & operator = (Queue right);

int getSize() const; //return current size

bool isEmpty() const; //check if there is no node in the queue

char top() const; //return the element at the front of the queue

//add a node to the end of the queue and pointed by the tail pointer

void push(char x);

//remove the node from the front of the queue

void pop();

private:

Node * head;

Node * tail;

int size;

};

#endif

The testing code is also provided for you to use the queue class you implemented to do a palindrome test.

The following is the testing code. You do not have to modify the testing code.

#include "Queue.h"

#include

#include

#include

void palindromeTest(string str);

bool isPalindrome(Queue q, stack s);

int main()

{

string test1 = "madam";

string test2 = "nurses run";

string test3 = "random sentence";

string test4 = "A man, a plan, a canal, panama!";

string test5 = "Luis Severino Stifles Red Sox and Makes His Wild-Card Case";

palindromeTest(test1);

palindromeTest(test2);

palindromeTest(test3);

palindromeTest(test4);

palindromeTest(test5);

system("pause");

return 0;

}

void palindromeTest(string str)

{

Queue myQueue;

stack myStack;

for(int i=0; i

{

if(isalpha(str[i]))

{

myQueue.push(tolower(str[i]));

myStack.push(tolower(str[i]));

}

}

if(isPalindrome(myQueue, myStack))

cout

else

cout

}

//This function will call class Queue's copy constructor, deep copy is a must

bool isPalindrome(Queue q, stack s)

{

while(q.isEmpty() == false)

{

char c1 = q.top();

char c2 = s.top();

if(c1 != c2)

return false;

q.pop();

s.pop();

}

return true;

}

head sizetail head size tail 1 head sietail i7e 4

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!