
COMPUTER SCIENCE
-JAVA-
1.Implement the abstract data type Stack using an array. You may use the following declaration for a static stack:
class Stack
{
int size;
int top;
int[] arr;
};
The operations to be implemented include CreateStack(), PushStack(), PopStack().
2.Write a corresponding JAVA
3.Write a Java method that reads a list of integers and when user enters (-1) key prints them in reverse order. This is a very simple method that creates a stack, reads a series of numbers and pushes them onto the stack. When the user keys end of file, the program pops the stack and prints the numbers in reverse order.

Step by stepSolved in 3 steps with 2 images

- 1. Java provides one interface to sort objects of user defined types. What is the name of this interface type. Use an example to describe how to implement this interface. (You answer must be within 5 lines) 2. Suppose I add the following numbers 1, 2, 3, 4, 5 into a Stack, and then remove two numbers from the Stack. What are the remaining numbers in the Stack? Now suppose I add the following numbers 1, 2, 3, 4, 5 into a Queue, and then remove two numbers from the Queue. What are the remaining numbers in the Queue? (You answer must be within 2 lines) 3. In our demo program, we compared the efficiency of ArrayList and LinkedList by adding a number of items to beginning of these two kinds of lists. Which kind of list (ArrayList or LinkedList) takes less time to add? Briefly explain why is that? You may diagrams to explain. 4. To respond to a button event, which overriding method should be implemented in a listener. Use an implementation example to explain. (You answer must be within 5…arrow_forwardC# Display the stack with the given information: int topNum; NumberStack stack2 = new NumberStack(5); stack2.Push(5);stack2.Push(7);stack2.Push(12);stack2.Push(3); public void PrintStack() { //Loop through each element of the stack and display it for (int i = size - 1 ; i >= 0; i--) { Console.WriteLine(stack[i]); } }arrow_forwardCreate a programme that sorts a stack so that the smallest things appear on top. You may use a second temporary stack, but you must not duplicate the components into another data structure (such as an array). The following operations are supported by the stack: push, pop, peek, and is Empty.arrow_forward
- Write a Java program using Stack class to demonstrate the following activities: Create three empty stacks named stack1, stack2 and stack3 respectively. Push the numbers [6,4,9] into stack1 and [1,2,3] into stack2. Pop the top number of stack1 and top number of stack2 and multiply them. Then, push the multiplication result into stack3. Pop the top number of stack1 and top number of stack2 and divide them. Push the result of division into stack3. Print Stack1, stack2 and stack3. Print the largest number in stack3arrow_forwardProject Overview: This project is for testing the use and understanding of stacks. In this assignment, you will be writing a program that reads in a stream of text and tests for mismatched delimiters. First, you will create a stack class that stores, in each node, a character (char), a line number (int) and a character count (int). This can either be based on a dynamic stack or a static stack from the book, modified according to these requirements. I suggest using a stack of structs that have the char, line number and character count as members, but you can do this separately if you wish.Second, your program should start reading in lines of text from the user. This reading in of lines of text (using getline) should only end when it receives the line “DONE”.While the text is being read, you will use this stack to test for matching “blocks”. That is, the text coming in will have the delimiters to bracket information into blocks, the braces {}, parentheses (), and brackets [ ]. A string…arrow_forwardjava /* Practice Stacks and ourVector Write a java program that creates a stack of integers. Fill the stack with 30 random numbers between -300 and +300. A)- With the help of one ourVector Object and an additional stack, reorganize the numbers in the stack so that numbers smaller than -100 go to the bottom of the stack, numbers between -100 and +100 in the middle and numbers larger than +100 in the top (order does not matter) B)- (a little harder) Solve the same problem using only one ourVector object for help C)- (harder) Solve the same problem using only one additional stack as a helper */ public class HWStacks { public static void main(String[] args) { // TODO Auto-generated method stub } }arrow_forward
- Java data strucarrow_forwardPlease help with the following in Java Write a Java program create a stack with elements pushed 1, 2, 3, 4 and 5, removes the middle element. Note that you may use only push(), pop(), peek() and empty() methods of the stack.arrow_forwardOCaml Code: The goal of this project is to understand and build an interpreter for a small, OCaml-like, stackbased bytecode language. Make sure that the code compiles correctly and provide the code with the screenshot of the output. Make sure to have the following methods below: -Push integers, strings, and names on the stack -Push booleans -Pushing an error literal or unit literal will push :error: or :unit:onto the stack, respectively -Command pop removes the top value from the stack -The command add refers to integer addition. Since this is a binary operator, it consumes the toptwo values in the stack, calculates the sum and pushes the result back to the stack - Command sub refers to integer subtraction -Command mul refers to integer multiplication -Command div refers to integer division -Command rem refers to the remainder of integer division -Command neg is to calculate the negation of an integer -Command swap interchanges the top two elements in the stack, meaning that the…arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education





