LinkedStackItem Class |
The LinkedStack class represents a last-in-first-out (LIFO) stack of generic items. So named to avoid conflict with the .NET framwork StackT class. Since C# strictly does not allow static class with instances, the implementation is effectively the same as the Stack class implementation.
It supports the usual Push and Pop operations, along with methods for peeking at the top item, testing if the stack is empty, and iterating through the items in LIFO order.
This implementation uses a singly-linked list with a nested, non-static class Node and hence is the same as the Stack class in algs4.jar. The Push, Pop, Peek, Count, and IsEmpty operations all take constant time in the worst case.
Namespace: Algs4Net
The LinkedStackItem type exposes the following members.
Name | Description | |
---|---|---|
![]() | LinkedStackItem |
Initializes an empty stack. |
Name | Description | |
---|---|---|
![]() | GetEnumerator |
Returns an iterator that iterates over the items in this queue in FIFO order. |
![]() ![]() | MainTest |
Demo test the LinkedStack data type. |
![]() | Peek |
Returns (but does not remove) the item most recently added to this stack. |
![]() | Pop |
Removes and returns the item most recently added to this stack. |
![]() | Push |
Adds the item to this stack. |
![]() | ToString |
Returns a string representation of this stack. (Overrides ObjectToString.) |
This class is a C# port from the original Java class LinkedStack implementation by Robert Sedgewick and Kevin Wayne.