在鏈表尾部添加數據的代碼如下:
//尾部添加數據
/// <summary>
/// 尾部添加數據
/// </summary>
/// <param name="DataValue"></param>
public void Append(int DataValue)//,int DataCurrent)
{
ListNode NewNode = new ListNode(DataValue);//,DataCurrent);
if (IsNull())
//如果頭指針為空
{
Head = NewNode;
Tail = NewNode;
}
else
{
Tail.Next = NewNode;
NewNode.Previous = Tail;
Tail = NewNode;
}
Current = NewNode;
//鏈表數據個數加一
ListCountValue += 1;
}
刪除當前位置的結點的代碼如下:
//刪除當前的數據
/// <summary>
/// 刪除當前的數據
/// </summary>
public void Delete()
{
//若為空鏈表
if (!IsNull())
{
//若刪除頭
if (IsBof())
{
Head = Current.Next;
Current = Head;
ListCountValue -= 1;
return;
}
//若刪除尾
if (ISEOf())
{
Tail = Current.Previous;
Current = Tail;
ListCountValue -= 1;
return;
}
//若刪除中間數據
Current.Previous.Next = Current.Next;
Current = Current.Previous;
ListCountValue -= 1;
return;
}
}