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 movieStack = new Stack();
  10. movieStack.Push ("Sinners");
  11. movieStack.Push ("Band of Brothers");
  12. movieStack.Push ("13 Hours");
  13. movieStack.Push ("Fast and Furious");
  14. movieStack.Push ("The Accountant");
  15. movieStack.Push ("Pulp Fiction"); // ... wait a minute ... its was Caddy Shack, Caddy Shack II was a really bad movie
  16. movieStack.Pop (); // remove Caddy Shack II
  17. movieStack.Push ("Avatar"); // add Caddy Shack to my list
  18. Console.WriteLine("Contents of Pat's 6 favorite comedy movies ...");
  19.  
  20. // print all of my favorite movies
  21. foreach(string movie in movieStack) {
  22. Console.WriteLine(movie);
  23. } // foreach
  24.  
  25. Console.WriteLine("\n\nPopping the Stack ...\n"); // skip a few lines
  26.  
  27. while(movieStack.Count > 0) {
  28. string movie = (string) movieStack.Pop ();
  29. Console.WriteLine("Popping {0}", movie );
  30. } // while
  31.  
  32. } // main
  33.  
  34. } // class Stack Sample
  35.  
Success #stdin #stdout 0.02s 26192KB
stdin
Standard input is empty
stdout
Contents of Pat's 6 favorite comedy movies ...
Avatar
The Accountant
Fast and Furious
13 Hours
Band of Brothers
Sinners


Popping the Stack ...

Popping Avatar
Popping The Accountant
Popping Fast and Furious
Popping 13 Hours
Popping Band of Brothers
Popping Sinners