The purpose of this assignment is to familiarize you with st
The purpose of this assignment is to familiarize you with stacks and queues. The assignment is split into 2 tasks.
The first part of the assignment is to take the Node, Stack, and Queue files and implement them (IE fill in the methods). Do not extend your class. References are to be singly linked.
Part two requires you to create another class to implement a Palindrome detector that uses a Stack and a Queue. It must fulfill the following requirements: 1. The program must loop to take input from the user. The input is a single word. If the word is quit, go to step 4. Otherwise we look to see if the input is an Palindrome (lowercase and uppercase are considered the same letter) 2. It must use both the Stack and the Queue you just wrote to detect Palindromes. 3. Output whether or not the inputed string is an Palindrome. 4. Once the user types quit, print out all the detected Palindromes in reverse order, then terminate. Use the proper data structure. 5. You cannot use array
Rather than detecting if a word is a palindrome, instead tell me if an entire String is a palindrome. An entire String is a palindrome iff the string reads the same backwards to forwards, ignoring capitalization and punctuation. , the following line should be detected as a Palindrome.
\"Go hang a salami, I’m a lasagna hog\"
public class Node<E> {
E element;
Node<E> next;
public Node() {
this.element = null;
this.next = null;
}
public Node(E e) {
this.element = e;
this.next = null;
}
public E getElement() {
return this.element;
}
public void setElement(E element) {
this.element= element;
}
}
/*
* Implement a reference based queue
*/
public class Queue<E> {
private Node<E> front;
private Node<E> back;
public Queue() {
this.front = null;
this.back = null;
}
Here queue class
/*
* places element in the back of the Queue
*/
public boolean enqueue(E element){
Node<E> node = new Node<E>(element);
if (isEmpty()){
front = node;
back= node;
}else {
back.next = node;
back =node;
}
return true ;
}
/*
* remove the front node of the queue and return it
*/
public E dequeue(){
//Fill in;
if (isEmpty()){
return null;
} else {
E retval = front.element;
front = front.next;
return retval;
}
}
// * Look at the front of the queue and return it, without removing
public E peek(){
//Fill in;
return front.element; //replace
}
public boolean isEmpty(){
return front == null;
}
//returns the size of the queue
public int size(){
return 0; //replace
}
}
Here stack
/*
* Implement a reference based stack
*/
public class Stack<E> {
private Node<E> top;
public Stack() {
this.top =null;
}
/*
* places element on the top of the stack
*/
public void push(E element){
Node<E> newTop = new Node<E>(element);
newTop.next = top;
top = newTop;
}
/*
* remove the top node and return its contents
*/
public E pop(){
//Fill in;
if (top == null){
return null;
} else {
E topItem = top.element;
top = top.next;
return topItem;
}//replace
}
/*
* Look at the top element of the Stack and return it, without removing
*/
public E peek(){
//Fill in;
return top.element; //replace
}
//returns the size of the stack
public int size(){
return 0; //replace
}
}
Solution
#include <stdio.h>
#include <string.h>
void push(char);
char pop();
char stack[100];
int top = -1;
void main()
{
char str[100];
int i, count = 0, len;
printf(\"Enter string to check it is palindrome or not : \");
scanf(\"%s\", str);
len = strlen(str);
for (i = 0; i < len; i++)
{
push(str[i]);
}
for (i = 0; i < len; i++)
{
if (str[i] == pop())
count++;
}
if (count == len)
printf(\"%s is a Palindrome string\ \", str);
else
printf(\"%s is not a palindrome string\ \", str);
}
void push(char c)
{
stack[++top] = c;
}
char pop()
{
return(stack[top--]);
}





