Question: 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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!