Skip to content

Instantly share code, notes, and snippets.

@danalexilewis
Last active August 29, 2015 14:17
Show Gist options
  • Save danalexilewis/bd82aa16b2d0a8f7f186 to your computer and use it in GitHub Desktop.
Save danalexilewis/bd82aa16b2d0a8f7f186 to your computer and use it in GitHub Desktop.
Demo of C# Diy Stack
using System;
using System.Collections;
namespace StackQueue
{
public class MyStack
{
object[] store = new object[0];
public void Push(object x)
{
object[] new_store = new object[store.Length +1];
new_store[new_store.Length -1] = x;
store = new_store;
}
public object Pop()
{
object last = store[store.Length - 1];
object[] new_store = new object[store.Length -1];
for (int i = 0; i < new_store.Length; i++)
{
new_store[i] = store[i];
}
store = new_store;
return last;
}
public object Peek()
{
return store.Last();
}
public bool Empty()
{
if (store.Length > 0)
{
return false;
}
else
{
return true;
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment