Click or drag to resize
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.

Inheritance Hierarchy
SystemObject
  Algs4NetLinkedStackItem

Namespace: Algs4Net
Assembly: Algs4Net (in Algs4Net.dll) Version: 1.0.0.0 (1.0.0.0)
Syntax
C#
public class LinkedStack<Item> : IEnumerable<Item>, 
	IEnumerable

Type Parameters

Item

The LinkedStackItem type exposes the following members.

Constructors
Properties
  NameDescription
Public propertyCount
Returns the number of items in the stack.
Public propertyIsEmpty
Is this stack empty?
Top
Methods
  NameDescription
Public methodGetEnumerator
Returns an iterator that iterates over the items in this queue in FIFO order.
Public methodStatic memberMainTest
Demo test the LinkedStack data type.
Public methodPeek
Returns (but does not remove) the item most recently added to this stack.
Public methodPop
Removes and returns the item most recently added to this stack.
Public methodPush
Adds the item to this stack.
Public methodToString
Returns a string representation of this stack.
(Overrides ObjectToString.)
Top
Remarks
For additional documentation, see Section 1.3 of Algorithms, 4th Edition by Robert Sedgewick and Kevin Wayne.

This class is a C# port from the original Java class LinkedStack implementation by Robert Sedgewick and Kevin Wayne.

See Also