fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Collections; // For old-style ArrayList
  4. class StackSample
  5. {
  6.  
  7. static void Main(string[] args)
  8. {
  9. Stack surfbreakStack = new Stack();
  10. surfbreakStack.Push ("Animal House");
  11. surfbreakStack.Push ("Stripes");
  12. surfbreakStack.Push ("Ghost Busters");
  13. surfbreakStack.Push ("Wayne's World");
  14. surfbreakStack.Push ("Happy Gilmore");
  15. surfbreakStack.Push ("Caddy Shack II"); // ... wait a minute ... it was Caddy Shack
  16. surfbreakStack.Pop (); // remove Caddy Shack II
  17. surfbreakStack.Push ("Caddy Shack"); // add Caddy Shack to my list
  18.  
  19. Console.WriteLine("Contents of Tim's 6 favorite comedy movies ...");
  20.  
  21. // print all of my favorite movies
  22. foreach(string surfbreak in surfbreakStack) {
  23. Console.WriteLine(surfbreak);
  24. } // foreach
  25.  
  26. Console.WriteLine("\n\nPopping the Stack ...\n"); // skip a few lines
  27.  
  28. while(surfbreakStack.Count > 0) {
  29. string surfbreak = (string) surfbreakStack.Pop ();
  30. Console.WriteLine("Popping {0}", surfbreak );
  31. } // while
  32.  
  33. } // main
  34.  
  35. }
Success #stdin #stdout 0.03s 24236KB
stdin
Standard input is empty
stdout
Contents of Tim's 6 favorite comedy movies ...
Caddy Shack
Happy Gilmore
Wayne's World
Ghost Busters
Stripes
Animal House


Popping the Stack ...

Popping Caddy Shack
Popping Happy Gilmore
Popping Wayne's World
Popping Ghost Busters
Popping Stripes
Popping Animal House