Skip to content

Instantly share code, notes, and snippets.

@NightBrownie
Created May 13, 2011 16:04
Show Gist options
  • Save NightBrownie/970805 to your computer and use it in GitHub Desktop.
Save NightBrownie/970805 to your computer and use it in GitHub Desktop.
Stack
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Lab_3_inisp
{
class ListItem<T>
{
public ListItem<T> Next
{ get; set; }
public T Value
{ get; set; }
public ListItem(T _value, ListItem<T> _next)
{
Next = _next;
Value = _value;
}
}
class List<T>
{
private ListItem<T> Head;
public List()
{
Head = null;
}
public void Push(T _value)
{
ListItem<T> BufferItem = new ListItem<T>(_value, Head);
Head = BufferItem;
}
public T Pop()
{
if (Head != null)
{
T BufferValue = Head.Value;
Head = Head.Next;
return BufferValue;
}
else
return default(T);
}
public bool Contains(T _value)
{
bool Result = false;
ListItem<T> ListPointer = Head;
while (ListPointer != null)
if (ListPointer.Value.Equals(_value))
{
Result = true;
break;
}
return Result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment