peek method
E
peek()
Returns the top element of the stack without removing it.
Throws NoGuaranteeException if the stack is empty.
Example:
final stack = LinkedStack<int>();
stack.push(100);
print(stack.peek()); // 100
print(stack.length); // 1 (element still in stack)
Implementation
E peek() {
if (_top == null) {
throw NoGuaranteeException('Stack is empty');
}
return _top!.data;
}