Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

what is the time complexity for this program. Select the right answer: A- theta(nlogn). B- O(logn). >>>>>>>>>> < < < < < < < <

what is the time complexity for this program. Select the right answer:

A- theta(nlogn).

B- O(logn).

>>>>>>>>>><<<<<<<<<<<<<<

import java.io.*; import java.util.*; public class test { // This is the temporary stack static Stack res = new Stack(); static Stack tmpStack = new Stack(); // Sorts input stack and returns // sorted stack. static void sortStack(Stack input) { while (input.size() != 0) { // pop out the first element int tmp = input.peek(); input.pop(); // while temporary stack is not empty and // top of stack is greater than temp while (tmpStack.size() != 0 && tmpStack.peek() < tmp) { // pop from temporary stack and push // it to the input stack input.push(tmpStack.peek()); tmpStack.pop(); } // push temp in tempory of stack tmpStack.push(tmp); } } static void sortedMerge(Stack s1) { while (s1.size() != 0) { res.push(s1.peek()); s1.pop(); } // Sort the result stack. sortStack(res); } // main function public static void main(String args[]) { Stack s1 = new Stack(); s1.push(34); s1.push(3); s1.push(31); s1.push(1); s1.push(12); s1.push(23); sortedMerge(s1); System.out.println("Sorted and merged stack :"); while (tmpStack.size() != 0) { System.out.print(tmpStack.peek() + " "); tmpStack.pop(); } } }

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

Sql++ For Sql Users A Tutorial

Authors: Don Chamberlin

1st Edition

0692184503, 978-0692184509

More Books

Students also viewed these Databases questions

Question

Explain the importance of nonverbal messages.

Answered: 1 week ago

Question

Describe the advantages of effective listening.

Answered: 1 week ago

Question

Prepare an employment application.

Answered: 1 week ago