
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
expand_more
expand_more
format_list_bulleted
Question
![QUESTION 4
public class StackTest{
public static void main(String[] args){
Stack s = new Stack();
for(int i = 0; i< 10; i++)
s.push(i);
s.pop();
s.pop();
s.pop();
System.out.println(s.peek();
what is the output?
} }
O a. 6
O b.7
O C. 8
O d. 5](https://content.bartleby.com/qna-images/question/8ee73fc1-42c7-4597-ba94-6506ae498ed7/28cd09fc-aee9-42f3-9ebc-27cecb15d791/qz9ogggb_thumbnail.jpeg)
Transcribed Image Text:QUESTION 4
public class StackTest{
public static void main(String[] args){
Stack s = new Stack();
for(int i = 0; i< 10; i++)
s.push(i);
s.pop();
s.pop();
s.pop();
System.out.println(s.peek();
what is the output?
} }
O a. 6
O b.7
O C. 8
O d. 5
Expert Solution

This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution
Trending nowThis is a popular solution!
Step by stepSolved in 2 steps

Knowledge Booster
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.Similar questions
- Question 1 Analyze the following code: import java.util.*: public class Test { public static void main (String[] args){ PriorityQueue queue = new PriorityQueue( Arrays.asList (60, 10, 50, 30, 40, 20)): while (!queue.isEmpty()) System.out.print(queue.poll () + " "); O The program displays 10 20 30 40 50 60 O The program displays 60 50 40 30 20 10 The program displays 60 10 50 30 40 20 O There is no guarantee that the program displays 10 20 30 40 50 60 A Moving to the next question prevents changes to this answerarrow_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_forward0:00 I ZVV 58 Stack s - new Stack(); s. push(10); s. push(20); s. push(30); s. push(40); // stack created with elements- 10 20 30 40 59 60 61 62 63 64 65 sum(s); 66 public static void sum(stack s){ Integer sum = 0; stack tmp = new Stack(); // move the stack to new stack, it will be in reverse orde // simultaneously sum the elements while (Is.isEmpty())( tmp.push(s.pop(); sum t tmp.peek(); 67 68 69 70 71 72 73 74 sum t= tmp.peek (); 74 75 // move to original stack while (Itmp.isEmpty()){ s.push(tmp.pop()); system.out.println("sum= "+sum.tostring()); OUTPUT- 10 pushed into stack 20 pushed into stack 30 pushed into stack 40 pushed into stack 40 pushed into stack 30 pushed into stack 20 pushed into stack 10 pushed into stack 10 pushed into stack 20 pushed into stack 30 pushed into stack 40 pushed into stack Sum= 100 Sum of 10, 2O, 30, 40 = 100 I hope it helps. For any doubt, feel free to ask in comments, and give upvote if u get the answer.arrow_forward
- This is java. Write the java code that takes the contents of a stack and places it in a queue and takes the contents of a queue and puts it in a stack. Your code can only use stack and queue data structure. swapStackAndQueue(stack, queue) //method call This is java.arrow_forwardimport java.util.*;import java.io.*; public class HuffmanCode { private Queue<HuffmanNode> queue; private HuffmanNode overallRoot; public HuffmanCode(int[] frequencies) { queue = new PriorityQueue<HuffmanNode>(); for (int i = 0; i < frequencies.length; i++) { if (frequencies[i] > 0) { HuffmanNode node = new HuffmanNode(frequencies[i]); node.ascii = i; queue.add(node); } } overallRoot = buildTree(); } public HuffmanCode(Scanner input) { overallRoot = new HuffmanNode(-1); while (input.hasNext()) { int asciiValue = Integer.parseInt(input.nextLine()); String code = input.nextLine(); overallRoot =…arrow_forward
arrow_back_ios
arrow_forward_ios
Recommended textbooks for you
- 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

Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education

Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON

Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON

C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON

Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning

Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education