Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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++

image text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Processing

Authors: David M. Kroenke

12th Edition International Edition

1292023422, 978-1292023427

More Books

Students also viewed these Databases questions

Question

Organize and support your main points

Answered: 1 week ago

Question

Move smoothly from point to point

Answered: 1 week ago

Question

Outlining Your Speech?

Answered: 1 week ago