Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

( 3 5 points ) Given Node.java and SinglyLinkedList.java, answer the following questions: a . ( 1 5 points ) Write a method that gets

(35 points) Given Node.java and SinglyLinkedList.java, answer the following questions:
a.(15 points) Write a method that gets a SinglyLinkedList object of numbers and a value max and removes every number greater than max in the list.
Example: if list=[5,10,15,7,3,27,14,1], max =13, list should be shortened by the following method and becomes [5,10,7,3,1]:
public static void removeValuesLargerThanMax(SinglyLinkedList list, int max){...}
b.(20 points) Bob has n pens labeled by 1,2,3,..., n. He uses pen #1 for day 1 of school, pen #2 for day 2, pen #3 for day 3,... and pen #n for day n of school. For day n+1 of school, he uses pen #1 again. And this process continues in a round-robin fashion! Assume that Bob loses a pen every k days; i.e. he loses a pen on day k, another one on day 2k, etc. Write a method using the given SinglyLinkedList that gets the values of n and k, and returns the label of last remaining pen before Bob loses all its pens.
Example 1: n =5, k =1, the last pen is #5 since Bob loses a pen every day and #5 is the last pen Bob uses.
Example 2: n =5, k =2,
After day 2, pens are [1,3,4,5]
After day 4, pens are [1,3,5]
After day 6, pens are [3,5]
After day 8, pens are [3]
Last pen is #3
public static int bobsLastPen(int numberOfPens, int k){...}
4.(15 points) Solve part (a) of question 3 using java.util.LinkedList; i.e. implement the following method:
public static void removeValuesLargerThanMax(LinkedList list, int max){...}
5.(20 points) Write a Java method that uses java.util.Stack class to implement the following method:
public static boolean isBalanced(String input, char[] openingSymbols, char[] closingSymbols){...}
The method checks whether the input string is made of balanced sequence of parentheses, brackets, braces, etc. For example, assuming that input is "{1+(2+3*[4^x])-7}", openingSymbols is an array made of (,[, and {, and closingSymbols is another array made of ),], and }, the method must return true. However, if the input is "{1+(2+3*[4^x]}-7)", with the same mentioned opening and closing symbols, the method must return false since the opening and closing symbols are not balanced.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions