Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Using java, Add a method to the LinkedStack class (code below) called removeBottomHalf which removes the half of the elements at the bottom of the

Using java, Add a method to the LinkedStack class (code below) called removeBottomHalf which removes the half of the elements at the bottom of the stack. Text the method usinga driver program and find the time complexity of the method.

// This class implements a Stack ADT as a linked list public class LinkedStack { LinkedNode front; // Reference to the first LinkedNode in the list int count; // Number of nodes in the list // Constructor - initializes the front and count variables LinkedStack() { front = null; count = 0; } // Implements the push operation void push(int x) { LinkedNode newNode = new LinkedNode(x); newNode.next = front; front = newNode; count++; } // Implements the pop operation int pop() { int x = front.x; front = front.next; count--; return x; } // Implements the peek operation int peek() { return front.x; } // Implements the isEmpty operation boolean isEmpty() { return front==null; } // Implements the size operation int size() { return count; } // This method returns a String containing // a space separated representation of the underlying linked list public String toString() { String str = ""; LinkedNode cur = front; while (cur!=null) { str += cur.x + " "; cur = cur.next; } return str; } }

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

Step: 3

blur-text-image

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

Database Management Systems Designing And Building Business Applications

Authors: Gerald V. Post

1st Edition

0072898933, 978-0072898934

More Books

Students also viewed these Databases questions