Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

THE PROGRAM MUST BE IN JAVA 1.You should do the problem with stacks to solve the problem 2.You are not supposed to use java libraries.

THE PROGRAM MUST BE IN JAVA

1.You should do the problem with stacks to solve the problem

2.You are not supposed to use java libraries. You need to implement your own data

structures to solve the problems.

image text in transcribed

Please I need help

There is a bag-like data structure, supporting two opcrations: Throw an element x into the bag Take out an clement from the ba Given a sequence of operations with return values, you're going to guess the data structure. It a stack Last-In. First-Out), a queue (Pirst-In, First-Out) a priority-queue (Always take out larg elements first) or something else that you can hardly imagine! Input There are several test cases. Each test case begins with a line conta ning a single mteger n (1 T 1000. Each of the next lines is either a type-1 command, or an integer 2 followed by an integer That means after executing a type-2 command, we get an element z without error. The value of is always a positive integer not larger than 100. The input is terminated by end-of-file (EOF). Output For each test case, output one of the following: It's definitely a stack. It's definitely a queue It's defiitely a priority queue It can't be a stack, a queue or a priority queue It can be more than one of the three data structures men- tioned above stack eue riority que eue impossible not sure Sample Input 1 2 1 3 2 3 1 2 2 3 7 1 2 1 3 2 5 1 4 2 4 Sample Output queue not sure impossible stack priority queue There is a bag-like data structure, supporting two opcrations: Throw an element x into the bag Take out an clement from the ba Given a sequence of operations with return values, you're going to guess the data structure. It a stack Last-In. First-Out), a queue (Pirst-In, First-Out) a priority-queue (Always take out larg elements first) or something else that you can hardly imagine! Input There are several test cases. Each test case begins with a line conta ning a single mteger n (1 T 1000. Each of the next lines is either a type-1 command, or an integer 2 followed by an integer That means after executing a type-2 command, we get an element z without error. The value of is always a positive integer not larger than 100. The input is terminated by end-of-file (EOF). Output For each test case, output one of the following: It's definitely a stack. It's definitely a queue It's defiitely a priority queue It can't be a stack, a queue or a priority queue It can be more than one of the three data structures men- tioned above stack eue riority que eue impossible not sure Sample Input 1 2 1 3 2 3 1 2 2 3 7 1 2 1 3 2 5 1 4 2 4 Sample Output queue not sure impossible stack priority queue

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored 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

Recommended Textbook for

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions