COMPUTER SCIENCE AND ENGINEERING
DATA STRUCTURES
Question
[CLICK ON ANY CHOICE TO KNOW THE RIGHT ANSWER]
|
|
Peek
|
|
Pop
|
|
Push
|
|
None of the above
|
Detailed explanation-1: -There is another important operation that can be applied on stacks-the peek method. This method returns the top element from the stack without deleting it from the stack.
Detailed explanation-2: -top() is used to access the element at the top of the stack container. In a stack, the top element is the element that is inserted at the last or most recently inserted element.
Detailed explanation-3: -peek() method in Java is used to retrieve or fetch the first element of the Stack or the element present at the top of the Stack. The element retrieved does not get deleted or removed from the Stack. Syntax: STACK.peek()
Detailed explanation-4: -This end is called the top of the stack. Since the element at the top of the stack is the most recently inserted element using the insert operation, and it is also the one to be removed first by the delete operation, the stack is called a Last In First Out (LIFO) list.