Write a Java public static general function which doesn't belong to the Stack class, isGreaterThan that determines if one stack is greater than another stack. If the summation of every other item(starting at the top) from one stack is greater than the summation of every other item(starting at the top) from another, return true, otherwise, return false. After you call this method, both stacks should stay the same as they are called before.
Receives: a Stack type argument S1 and another Stack type argument S2
Postcondition: If the summation of every other item (starting at the top) from S1 is greater than the summation of every other item (starting at the top) from S2, return true, otherwise, return false. Both S1 and S2 should stay the same as they are called before.
public static boolean isGreaterThan(Stack S1, Stack S2)
Trending nowThis is a popular solution!
Step by stepSolved in 3 steps with 3 images
- input: 23+7* 26+9/ 14 2 + 160/ 99 2 + 50/24 - 100 4/3 * 20 + 143 *19 + 12/3+7* 23 7 + 10 * 14 + 19 - 22 * 16/ output: expression 23 +7* evaluates to 35 expression 2 6 + 9 / evaluates to 0 expression 14 2 + 160/ evaluates to 0 expression 99 2 + 50 / 24 - evaluates to -22 expression 100 4/3 * 20+ evaluates to 95 expression 14 3 * 19 + 12/3 + 7* evaluates to 56 expression 23 7 + 10 * 14 + 19 - 22 * 16/ evaluates to 405arrow_forwarddon't use others answers java 1. Write a generic static method that takes a Stack of any type element as a parameter, pops each element from the stack, and prints it. It should have a type parameter that represents the Stack’s element type.arrow_forwardexamine a very simple task: reversing a word. When you run the program, it asks you to type in a word. When you press Enter, it displays the word with the letters in reverse order. A stack is used to reverse the letters. First the characters are extracted one by one from the input string and pushed onto the stack. Then they’re popped off the stack and displayed. Because of its last-in-first-out characteristic, the stack reverses the order of the characters.arrow_forward
- Explore the stack's capabilities when allowed to be itself.arrow_forwardstacks and queues. program must be able to handle all test cases without causing an exception Note that this problem does not require recursion to solve (though you can use that if you wish).arrow_forwardQuestion 2 You have been provided with the following elements 10 20 30 40 50 ● . ● ● Write a Java program in NetBeans that creates a Stack. Your Java program must use the methods in the Stack class to do the following: Add the above elements into the Stack Display all the elements in the Stack Get the top element of the Stack and display it to the user i. ii. iii.arrow_forward
- Project 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_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_forwardGiven a stack, a function is consecutive takes a stack as a parameter and thatreturns whether or not the stack contains a sequence of consecutive integersstarting from the bottom of the stack (returning true if it does, returningfalse if it does not). For example:bottom [3, 4, 5, 6, 7] topThen the call of is_consecutive(s) should return true.bottom [3, 4, 6, 7] topThen the call of is_consecutive(s) should return false.bottom [3, 2, 1] top The function should return false due to reverse order. Note: There are 2 solutions:first_is_conse cutive: it uses a single stack as auxiliary storagesecond_is_cons ecutive: it uses a single queue as auxiliary storagearrow_forward
- Computer Networking: A Top-Down Approach (7th Edi...Computer EngineeringISBN:9780133594140Author:James Kurose, Keith RossPublisher:PEARSONComputer Organization and Design MIPS Edition, Fi...Computer EngineeringISBN:9780124077263Author:David A. Patterson, John L. HennessyPublisher:Elsevier ScienceNetwork+ Guide to Networks (MindTap Course List)Computer EngineeringISBN:9781337569330Author:Jill West, Tamara Dean, Jean AndrewsPublisher:Cengage Learning
- Concepts of Database ManagementComputer EngineeringISBN:9781337093422Author:Joy L. Starks, Philip J. Pratt, Mary Z. LastPublisher:Cengage LearningPrelude to ProgrammingComputer EngineeringISBN:9780133750423Author:VENIT, StewartPublisher:Pearson EducationSc Business Data Communications and Networking, T...Computer EngineeringISBN:9781119368830Author:FITZGERALDPublisher:WILEY