Files
stgsharp/源代码/.Net/StgSharp/Logic/LinkedList.cs
T

61 lines
1.2 KiB
C#

using System;
using System.Collections.Generic;
using System.Text;
namespace StgSharp.Logic
{
public class LinkedList<T> where T: INode
{
private LinkedListNode<T> _head;
private LinkedListNode<T> _tail;
private LinkedListNode<T> _cache;
public T Head
{
get { return _head._this; }
set { _head = new LinkedListNode<T>(value); }
}
public T Tail
{
get { return _tail._this; }
set { _tail = new LinkedListNode<T>(value); }
}
public void Add(T t)
{
if (_head != default(LinkedListNode<T>))
{
Head = t;
}
else
{
_cache = new LinkedListNode<T>(t);
_tail._next = _cache;
_cache._previous = _tail;
_tail = _cache;
}
}
public void RemoveTail()
{
if (_tail==default(LinkedListNode<T>))
{
}
else
{
_cache = _tail;
_tail = _cache._previous;
_cache._previous = default(LinkedListNode<T>);
}
}
}
}