Question: 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 =

the push and pop method are below, please use the method belowthe 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!