Question

In: Computer Science

#data structures Assume you are given an implementation of the Stack class. Recall that it has...

#data structures
Assume you are given an implementation of the Stack class. Recall that it has methods push(), pop(), top(), isEmpty() and isFull(). Write an Integer function with prototype:
public static Integer popBottom(Stack<Integer> stk);
Note that it has one parameter, a single stack object stk. The function should delete the item at the bottom of the stack and return this item as the value of the function. If the stack is empty return null. When the function returns the stk should not otherwise be changed. You may not use arrays or queues – only Stack objects, Integer objects or ints. Make no assumptions about the implementation details of the stack object.

Solutions

Expert Solution

The logic and the function is as follows where we create a dummy stack and push the values and then we return the top value in dummy stack and then we push the elements back to the original stack.


Related Solutions

In this lab, using C++, you will create two data structures: a stack and a queue....
In this lab, using C++, you will create two data structures: a stack and a queue. You will use STL containers to demonstrate basic ADTs. Queue For the queue, you will simulate a buffer. Remember it is first-in-first-out. The user will enter a number for the number of rounds to run your simulation. You need one function that randomly generates a number. You will also have a user specified percentage, and the function uses this percentage to randomly put the...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you...
C++ Data Structures: Implement a Stack and a Queue using Linked list In this lab you will implement the functionality of a stack and a queue using a linked list. Your program must use of the declaration of the Stack and Queue class in Stack.h and Queue.h You have to implement the functionalities of queue (enq, deq, displayQueue) in a file called Queue.cpp. All the functions in Queue.cpp should follow the prototypes declared in Queue.h. Your code should make use...
1. Implement the stack abstract data type. Write it as a separate class called Stack. For...
1. Implement the stack abstract data type. Write it as a separate class called Stack. For simplicity the data type to be stored in the stack is String but you can also use generic type. 2. Test your class implementation by calling push() and pop(). If the stack is empty (size equals zero) pop() should return null and print that “stack is empty”. If stack is full (size equals max) push() returns false and prints that “stack is full”. This...
Given a class Stack with the interface public void push(char n) // pushes n onto stack...
Given a class Stack with the interface public void push(char n) // pushes n onto stack public char pop() // return the top of the stack, removing element from stack public boolean isEmpty() // return true if stack is empty Write a method public int removeX(Stack<Character> stack) which takes a stack of Characters, removes the occurrences of ‘X’ and returns the count of the number of Xs removed. It must restore the stack to its original order (less the Xs)....
Thoroughly explain the impacts of data structures and algorithms in the development and implementation of computer...
Thoroughly explain the impacts of data structures and algorithms in the development and implementation of computer programs using modern computer technologies.
Objective You are given a partial implementation of one header file, GildedRose.h. Item is a class...
Objective You are given a partial implementation of one header file, GildedRose.h. Item is a class that holds the information for each item for the inn. GildedRose is a class that holds an internal listing of many Item objects. This inventory should hold at least 10 items. For this you can use arrays, the std::array class, or even the vector class. Complete the implementation of these classes, adding public/private member variables and functions as needed. You should choose an appropriate...
please in java ! Assume you have a stack of integers. The stack contains same number...
please in java ! Assume you have a stack of integers. The stack contains same number of positive and negative integers. You want to organize it such that negative and positive integers alternate (+-+-.., or -+-+,..). A. Write a Java code that uses no more than two additional Stacks to solve the problem. Note: You do not need to write the code for Stacks, you are using a Stack from the library with a name ourStack and has the following...
Assume you have a stack of integers. The stack contains same number of positive and negative...
Assume you have a stack of integers. The stack contains same number of positive and negative integers. You want to organize it such that negative and positive integers alternate (+-+-.., or -+-+,..). A. Write a Java code that uses no more than two additional Stacks to solve the problem. Note: You do not need to write the code for Stacks, you are using a Stack from the library with a name ourStack and has the following interface: ourStack() constructor, pop,...
Given: You are given a Python Class template. In this class there is a class variable...
Given: You are given a Python Class template. In this class there is a class variable vector, is a list of N non-negative integers and are stored (in positions 0, 1, 2, ... (N-1)), where at least one integer is 0. Task: Write a recursive function "findAllPaths" to find all possible path through V starting at position 0, and ending at the location of 0, in accordance with the Rule below. If no such path exists, "paths" should be an...
You are given the following class definition (assume all methods are correctly implemented): public class Song...
You are given the following class definition (assume all methods are correctly implemented): public class Song { ... public Song(String name, String artist) { ... } public String getName() { ... } public String getArtist() { ... } public String getGenre() { ... } public int copiesSold() { ... } } Write NAMED and TYPED lambda expressions for each of the following, using appropriate functional interfaces from the java.util.function and java.util packages (Only the lambda expression with no type+name will...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT