I have a queue and stack class program that deals with a palindrome, I need someone to help to put in templates then rerun the code. I'd greatly appreciate it. It's in C++.
Here is my program:
#include<iostream>
#include<list>
#include<iterator>
#include<string>
using namespace std;
class Queue
{
public:
list <char> queue;
Queue()
{
list <char> queue;
}
void Push(char item)
{
queue.push_back(item);
}
char pop()
{
char first = queue.front();
queue.pop_front();
return first;
}
bool is_empty()
{
if(queue.empty())
{
return true;
}
else
{
return false;
}
}
};
class Stack
{
public:
list <char> stack;
Stack()
{
list <char> stack;
}
void Push(char item)
{
stack.push_front(item);
}
char pop()
{
char first = stack.front();
stack.pop_front();
return first;
}
bool is_empty()
{
if(stack.empty())
{
return true;
}
else
{
return false;
}
}
};
bool is_palindrome(string alphabet)
{
Stack stack;
Queue queue;
int i = 0;
while(alphabet[i] != 0)
{
stack.Push(alphabet[i]);
queue.Push(alphabet[i]);
i++;
}
while(!stack.is_empty() && !queue.is_empty())
{
if(stack.pop() != queue.pop())
{
return false;
}
}
return true;
}
int main()
{
string alphabet;
cout << "Please enter the alphabet: \n";
getline (cin, alphabet);
if(is_palindrome(alphabet))
{
cout<<"The given string is a palindrome"<<endl;
}
else
{
cout<<"The given string is not a
plaindrome"<<endl;
}
}
// C++ program to create template Stack and template Queue
#include<iostream>
#include<list>
#include<iterator>
#include<string>
using namespace std;
// create a generic Queue class
template <class T>
class Queue
{
private:
list <T> queue;
public:
Queue()
{}
void Push(T item)
{
queue.push_back(item);
}
T pop()
{
T first = queue.front();
queue.pop_front();
return first;
}
bool is_empty()
{
return(queue.empty());
}
};
// create a generic Stack class
template <class T>
class Stack
{
private:
list <T> stack;
public:
Stack()
{}
void Push(T item)
{
stack.push_front(item);
}
T pop()
{
T first = stack.front();
stack.pop_front();
return first;
}
bool is_empty()
{
return(stack.empty());
}
};
// function to determine the if the string is a palindrome or not
bool is_palindrome(string alphabet)
{
// create Stack and Queue of characters
Stack<char> stack;
Queue<char> queue;
int i = 0;
while(alphabet[i] != 0)
{
stack.Push(alphabet[i]);
queue.Push(alphabet[i]);
i++;
}
while(!stack.is_empty() && !queue.is_empty())
{
if(stack.pop() != queue.pop())
{
return false;
}
}
return true;
}
int main() {
string alphabet;
cout << "Please enter the string: \n";
getline (cin, alphabet);
if(is_palindrome(alphabet))
{
cout<<"The given string is a palindrome"<<endl;
}
else
{
cout<<"The given string is not a palindrome"<<endl;
}
return 0;
}
//end of program
Output:


I have a queue and stack class program that deals with a palindrome, I need someone...
#include <iostream> #include <stack> #include <queue> using namespace std; void printFromStack(string expr){ stack<char> myStack; for(int i=0; i<expr.length(); i++){ //Insert code here to push each character onto the stack } cout << "My stack is popped in this order" << endl; while(!myStack.empty()){ //Insert code here to cout the top of the stack one by one //Pop each one after it’s printed out } cout << endl; } void printFromQueue(string expr){ queue<char> myQueue; //Insert code here to push each character onto the...
Can anyone help me fix this program to make sure use stack and use STL library to check the name1 and name2 is palindrome. Thank you stackPalindrome.h #ifndef_STACK_PALINDROME_H #define_STACK_PALINDROME_H template <class StackPalindrome> class StackPalindrome { public: virtual bool isEmpty() const = 0; virtual bool push(const ItemType& newEntry) = 0; virtual bool pop() = 0; virtual ItemType peek() const = 0; }; #endif stack.cpp #include<iostream> #include<string> #include<new> #include "stackPalindrome.h" using namespace std; template <class ItemType> class OurStack...
Stack help. I need help with my lab assignment. Complete a method for a class named Palindrome that evaluates a string phrase to determine if the phrase is a palindrome or not. A palindrome is a sequence of characters that reads the same both forward and backward. When comparing the phrase to the same phrase with the characters in reverse order, an uppercase character is considered equivalent to the same character in lowercase, and spaces and punctuation are ignored. The...
can someone please fix this error in the stack file at line 18 ( class Stack2:public Stack { ) this is thew error ----> expected class name before '{' token Queue.h --> #include "Stack.hpp" template <typename ITEM> class Queue { private: ITEM item; Stack <ITEM> * s1= new Stack<ITEM>; Stack <ITEM> * s2= new Stack<ITEM>; public: Queue(){}; bool enqueue (ITEM item); bool dequeue (ITEM &item); bool check = true; ~Queue(); }; //this is the class which contains the functions of...
I need help fixing my code. My output should be the following. Hello, world! : false A dog, a panic in a pagoda : true A dog, a plan, a canal, pagoda : true Aman, a plan, a canal--Panama! : true civic : true If I had a hi-fi : true Do geese see God? : true Madam, I’m Adam. : true Madam, in Eden, I’m Adam. : true Neil, a trap! Sid is part alien! : true Never odd...
I was told I need three seperate files for these classes is there anyway to tie all these programs together into one program after doing that. I'm using netbeans btw. import java.util.ArrayList; import java.util.Scanner; /** * * */ public class MySorts { public static void main(String[] args) { Scanner input = new Scanner(System.in); String sentence; String again; do { System.out .println("Enter a sentence, I will tell you if it is a palindrome: ");...
Implement the stack queue data structure with a linked list implementation to get the given test code in driver.cpp to work properly: driver.cpp code: #include <iostream> #include "stackLL.h" using namespace std; int main() { /////////////Test code for stack /////////////// stackLL stk; stk.push(5); stk.push(13); stk.push(7); stk.push(3); stk.push(2); stk.push(11); cout << "Popping: " << stk.pop() << endl; cout << "Popping: " << stk.pop() << endl; stk.push(17); stk.push(19); stk.push(23); while( ! stk.empty() ) { cout << "Popping: " << stk.pop() << endl; }...
Hi, I need to change the conversion where stack is into a class stack and add a template <class type> PROMPT: write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. if the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. #include #include #include #include #include using namespace std; double conversion(string); int...
Hello, I have some errors in my C++ code when I try to debug it.
I tried to follow the requirements stated below:
Code:
// Linked.h
#ifndef INTLINKEDQUEUE
#define INTLINKEDQUEUE
#include <iostream>
usingnamespace std;
class IntLinkedQueue
{
private: struct Node {
int data;
Node *next;
};
Node *front; // -> first item
Node *rear; // -> last item
Node *p; // traversal position
Node *pp ; // previous position
int size; // number of elements in the queue
public:
IntLinkedQueue();...
Fix the function so that it checks if the string is a palindrome #include <iostream> using namespace std; //Fix the function so that it checks if the string is a palindrome //(same forwards as backwards ex: racecar / radar) bool is_palindrome(string str, int i){ //base cases if (/* add the condition */) return false; if (/* add the condition */) return true; //recursive call return is_palindrome(str, i-1); } int main(){ string x; cin >> x; if (is_palindrome(x,x.length())){...