Click or drag to resize
ResizingArrayStackItem Class

The ResizingArrayStack class represents a (LIFO) stack of generic items. 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 resizing array, which double the underlying array when it is full and halves the underlying array when it is one-quarter full. The Push and Pop operations take constant amortized time, whereas he Count, Peek, and IsEmpty operations takes constant time in the worst case.

Inheritance Hierarchy
SystemObject
  Algs4NetResizingArrayStackItem

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

Type Parameters

Item

The ResizingArrayStackItem 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 to this stack that iterates through the items in LIFO order.
Public methodStatic memberMainTest
Demo test for the ResizingArrayStack 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.
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 ResizingArrayStack implementation by Robert Sedgewick and Kevin Wayne.

See Also