Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the push and pop method are below, please use the method below to help me with this problem, public void push(int data){ Node newTop =

image text in transcribedthe push and pop method are below, please use the method below to help me with this problem,

public void push(int data){ Node newTop = new Node(data); //creates a new node if(head == null){ //check if the node is empty head = newTop; tail = newTop; }else{ //generic case to add to top of the stack tail.next = newTop; tail = tail.next; } size++; } //method to test pop() public void pop(){ if(isEmpty()){ head= null; tail = null; } //test if it's one node stack if(size ==1 ){ Node temp = head; head = tail = null; size = 0; } Node current = head; for( int i = 1; i   stack.java, implement another program, called prompts the user to enter a string of any length. Using class Stack, the program creates a stack object (see assignment 3 test program) and uses the object to reverse the input string and display both the original input string and the revered string. For example, if the user enters This is a test string The program output, including the prompt and input string, would be as follows: -jGRASP exec: java -ea ReverseString Enter a string: This is a test string Input String: Reversed String: This is a test string string test isa This -jGRASP: operation complete

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_2

Step: 3

blur-text-image_3

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

Oracle Database 10g Insider Solutions

Authors: Arun R. Kumar, John Kanagaraj, Richard Stroupe

1st Edition

0672327910, 978-0672327919

More Books

Students also viewed these Databases questions