Class StackExample

java.lang.Object
topics.foundation.structures.StackExample

public class StackExample extends Object

Legacy Stack Demonstration

Demonstrates the structural operations of the legacy java.util.Stack class. While originally designed to represent a Last-In-First-Out (LIFO) collection, its architectural inheritance from java.util.Vector exposes it to index-based operations that directly violate strict stack contracts.

Architectural Note: In modern Java development, java.util.ArrayDeque is strongly preferred for LIFO stack semantics, as it avoids the synchronized threading overhead of Vector and enforces a much stricter operational boundary.

Complexity

  • Time Complexity:
    • O(1) amortized for standard top-of-stack operations (push, pop, peek).
    • O(N) for inherited vector operations like indexed insertions or arbitrary object removals, which require array shifting.
  • Space Complexity: O(N) to maintain the underlying dynamically resizing array.
Author:
vicegd
  • Constructor Details

    • StackExample

      public StackExample()
  • Method Details

    • main

      public static void main(String[] args)
      Main execution entry point.
      Parameters:
      args - Command-line arguments (not utilized).