please work on java language The purpose of this assignment

please work on java language.

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

stack

import java.io.BufferedReader;

import java.io.IOException;

import java.io.InputStreamReader;

class Stack {

private int top;

private int item[];

Stack(int size) {

top = -1;

item = new int[size];

}

void pushItem(int data) {

if (top == item.length - 1) {

System.out.println(\"Stack is Full\");

} else {

item[++top] = data;

System.out.println(\"Pushed Item :\" + item[top]);

}

}

int popItem() {

if (top < 0) {

System.out.println(\"Stack Underflow\");

return 0;

} else {

System.out.println(\"Pop Item : \" + item[top]);

return item[top--];

}

}

}

class StackExample {

public static void main(String[] args) throws IOException {

Stack stk = new Stack(5);

boolean yes=true;

int choice;

BufferedReader is = new BufferedReader(new InputStreamReader(System.in));

  

do{

System.out.println(\"1).Push\ 2).Pop\ 3).Exit\ \ Enter Choice\");

choice = Integer.parseInt(is.readLine());

  

switch(choice)

{

case 1: System.out.println(\"Enter Push Item: \");

stk.pushItem(Integer.parseInt(is.readLine()));

break;

case 2: stk.popItem();break;

case 3: yes = false;break;

default: System.out.println(\"Invalid Choice\");

}

}while(yes==true);

  

}

}

please work on java language. The purpose of this assignment is to familiarize you with stacks and queues. The assignment is split into 2 tasks. The first part
please work on java language. The purpose of this assignment is to familiarize you with stacks and queues. The assignment is split into 2 tasks. The first part
please work on java language. The purpose of this assignment is to familiarize you with stacks and queues. The assignment is split into 2 tasks. The first part
please work on java language. The purpose of this assignment is to familiarize you with stacks and queues. The assignment is split into 2 tasks. The first part
please work on java language. The purpose of this assignment is to familiarize you with stacks and queues. The assignment is split into 2 tasks. The first part
please work on java language. The purpose of this assignment is to familiarize you with stacks and queues. The assignment is split into 2 tasks. The first part
please work on java language. The purpose of this assignment is to familiarize you with stacks and queues. The assignment is split into 2 tasks. The first part

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site