Stack Peek()
Returns the element at the `top` index: `return arr[top]`. It does NOT decrement the top pointer. This is O(1) time.
Loading...
Loading Curriculum...
Loading Subject...
Loading Topic...
Loading Lesson...
Loading Lab...
Peek (sometimes called Top or Front) allows you to read the next item without actually removing it from the data structure.
Returns the element at the `top` index: `return arr[top]`. It does NOT decrement the top pointer. This is O(1) time.
Returns the element at the `front` index: `return arr[front]`. It does NOT increment the front pointer. This is O(1) time.
Never call Peek on an empty Stack or Queue. You will either get garbage memory values (in C++) or an Index Out Of Bounds error. Always call `IsEmpty()` first.