Class TopDownStackIterable<T>

  • Type Parameters:
    T - the type of the items on the stack
    All Implemented Interfaces:
    Iterable<T>

    public class TopDownStackIterable<T>
    extends Object
    implements Iterable<T>
    Provides an iterable over a stack that iterates in order from top to bottom.

    Note: Java stacks natively iterate from bottom to top; C# stacks from top to bottom.

    • Constructor Detail

      • TopDownStackIterable

        public TopDownStackIterable​(Stack<T> stack)
        Construct a top-down iterable view of a stack
        Parameters:
        stack - the stack over which the top-down iterator will iterate
    • Method Detail

      • iterator

        public Iterator<T> iterator()
        Returns an iterator over elements in the stack, starting at the top of stack and proceeding to the bottom
        Specified by:
        iterator in interface Iterable<T>
        Returns:
        a descending Iterator.