using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
namespace CrackSoft.Collections
{
class OverflowStack : IEnumerable, ICollection
{
object syncRoot = new object();
LinkedList items;
int maxItems;
public OverflowStack(int capacity)
{
maxItems = capacity;
items = new LinkedList();
}
public OverflowStack(IEnumerable collection)
{
items = new LinkedList(collection);
maxItems = items.Count;
}
public void Push(T item)
{
if (items.Count == maxItems)
items.RemoveLast();
items.AddFirst(item);
}
public T Pop()
{
T item = items.First.Value;
items.RemoveFirst();
return item;
}
public T Peek()
{
return items.First.Value;
}
public void Clear()
{
items.Clear();
}
public bool IsEmpty
{
get { return Count == 0; }
}
#region IEnumerable Members
IEnumerator IEnumerable.GetEnumerator()
{
return items.GetEnumerator();
}
#endregion
#region IEnumerable Members
public IEnumerator GetEnumerator()
{
return items.GetEnumerator();
}
#endregion
#region ICollection Members
public void CopyTo(Array array, int index)
{
if (array is T[])
items.CopyTo((T[])array, index);
}
public int Count
{
get { return items.Count; }
}
public bool IsSynchronized
{
get { return false; }
}
public object SyncRoot
{
get { return syncRoot; }
}
#endregion
}
}