Skip to content

Instantly share code, notes, and snippets.

@balaam
Created April 28, 2019 18:27
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save balaam/76d5a2bb99537ea626c2a637025c2c5f to your computer and use it in GitHub Desktop.
Save balaam/76d5a2bb99537ea626c2a637025c2c5f to your computer and use it in GitHub Desktop.
using System;
using System.Collections;
using System.Collections.Generic;
class MainClass {
public static void PrintList<T>(List<T> l)
{
for (int i = l.Count - 1; i >= 0 ; i--)
{
Console.WriteLine(l[i].ToString());
}
}
public static void Push(char s, List<char> l)
{
l.Add(s); // adds to the back of the list, which we'll call the head.
}
public static char Pop(List<char> l)
{
char element = l[l.Count - 1];
l.RemoveAt(l.Count - 1);
return element;
}
public static void Main (string[] args) {
Console.WriteLine ("Push a, b, c");
List<char> l = new List<char>();
Push('a', l);
Push('b', l);
Push('c', l);
PrintList<char>(l);
Console.WriteLine ("Calling pop");
Console.WriteLine("Popped: " + Pop(l));
PrintList<char>(l);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment