logo Hurry, Grab up to 30% discount on the entire course
Order Now logo

Ask This Question To Be Solved By Our ExpertsGet A+ Grade Solution Guaranteed

expert
Saksham ChepruComputer science
(5/5)

739 Answers

Hire Me
expert
Manal ChiguerrNursing
(5/5)

717 Answers

Hire Me
expert
Jyotika DasguptaStatistics
(/5)

975 Answers

Hire Me
expert
Marcella ArguelloGeneral article writing
(5/5)

811 Answers

Hire Me
Java Programming

Write a method equals that takes as parameters two stacks of integers and returns true if the two stacks are equal and that returns false otherwise.

INSTRUCTIONS TO CANDIDATES
ANSWER ALL QUESTIONS

Problem 1

Use a stack to test for balanced parentheses, when scanning the following expressions. Only consider the parentheses [ , ] , ( , ) , { , } . Ignore the variables and operators.

You should read an integer N, which is the number of test cases. Each test case is placed on a separate line.

Sample input:

2

[ a + { b / ( c - d ) + e / (f + g ) } - h ]  

[ a { b + [ c ( d + e ) - f ] + g }  

Sample output:

true

false

 Problem 2

To convert a number from decimal to binary, you simply divide by two until a quotient of zero is reached, then use the successive remainders in reverse order as the binary representation. Use a stack to store the remainder of the division and finally print the binary representation. The first line of input N is the number test cases.

Sample Input

5

0

3

5

7

10

Sample Output:

0

11

101

111

1010

 Problem 3

Write a method equals that takes as parameters two stacks of integers and returns true if the two stacks are equal and that returns false otherwise. To be considered equal, the two stacks would have to store the same sequence of integer values in the same order. Your method is to examine the two stacks but must return them to their original state before terminating. You may use one stack as auxiliary storage. The first line of input contains the number of test cases N. After that, each test case will consist of two lines each representing a stack elements.

 Sample input

2

1 2 3 4 5

1 2 3 4 5 

1 2 3 4

5 6 7 8 9 10

Sample output:

true

false 

Problem 5: BONUS Implementing a Stack as a Linked Data Structure

Write the interface StackInt<E> that declares the four methods below. Then, write a class LinkedStack<E> that implements the interface StackInt<E> as a linked list. In other words, your LinkedStack will be built as a LinkedList but will perform as a Stack (concerning pushing, popping and the other operations). You will have to create your own inner class Node<E> and implement the following methods:

? E push (E obj): to push an element at the top of the stack

? E pop(): to remove and return the element at the top of the stack

? E peek(): to return the element at the top of the stack without removing it

? boolean isEmpty(): to check if the stack is empty

For testing purposes, we will unify the class E. Consider E to be a class called City. The City class should have the following attributes and methods:

  • private attribute: “name” of type String, representing the city’s name
  • private attribute: “country” of type String, representing the country of the city
  • a constructor that takes the name and country as parameters
  • getters and setters
  • toString method of the format: “city_name, countryName”. Example: “Beirut, Lebanon”

Sample Input:

StackBottom| Beirut, Lebanon| Saida, Lebanon| Cairo, Egypt | New York, United States | StackTop

Instructions:

1- Call the isEmpty() method and print “Empty” or “Not Empty” based on the result

2- Use the push method to push all of the elements as shown above

3- Call the peek() method and print the returned City

4- Call the pop() method and print the returned City

5- Call the peek() method and print the returned City

6- Call the isEmpty() method and print “Empty” or “Not Empty” based on the result.

Sample Output:

Empty

New York, United States

New York, United States

Cairo, Egypt

Not Empty

Related Questions

. The fundamental operations of create, read, update, and delete (CRUD) in either Python or Java

CS 340 Milestone One Guidelines and Rubric  Overview: For this assignment, you will implement the fundamental operations of create, read, update,

. Develop a program to emulate a purchase transaction at a retail store. This  program will have two classes, a LineItem class and a Transaction class

Retail Transaction Programming Project  Project Requirements:  Develop a program to emulate a purchase transaction at a retail store. This

. The following program contains five errors. Identify the errors and fix them

7COM1028   Secure Systems Programming   Referral Coursework: Secure

. Accepts the following from a user: Item Name Item Quantity Item Price Allows the user to create a file to store the sales receipt contents

Create a GUI program that:Accepts the following from a user:Item NameItem QuantityItem PriceAllows the user to create a file to store the sales receip

. The final project will encompass developing a web service using a software stack and implementing an industry-standard interface. Regardless of whether you choose to pursue application development goals as a pure developer or as a software engineer

CS 340 Final Project Guidelines and Rubric  Overview The final project will encompass developing a web service using a software stack and impleme