MCQ IN COMPUTER SCIENCE & ENGINEERING

COMPUTER SCIENCE AND ENGINEERING

DATA STRUCTURES

Question [CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
The output of the code below is ____ stack.push(10);stack.push(15);stack.push(20);stack.push(39);stack .pop()stack.push(35);System.out.println(stack.peek());
A
20
B
35
C
39
D
10
Explanation: 

Detailed explanation-1: -C++ Stack push () function is used for adding new elements at the top of the stack. If we have an array of type stack and by using the push() function we can insert new elements in the stack. The elements are inserted at the top of the stack.

Detailed explanation-2: -Time Complexity of Stack Operations Only a single element can be accessed at a time in stacks. While performing push() and pop() operations on the stack, it takes O(1) time.

Detailed explanation-3: -In computer science, a stack is an abstract data type that serves as a collection of elements, with two main operations: Push, which adds an element to the collection, and. Pop, which removes the most recently added element that was not yet removed.

There is 1 question to complete.