daily update on 20230525 by nitload youmu, ses00001 not solved
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using StgSharp.Logic;
|
||||
using StgSharp.Graphics;
|
||||
using StgSharp.Logic;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
@@ -9,43 +10,60 @@ namespace StgSharp
|
||||
public class LinkedList<T>:INode<LinkedList<T>>,IEnumerable where T: INode<T>
|
||||
{
|
||||
internal readonly ContainerNode<T> _heading;
|
||||
internal ContainerNode<T> _first;
|
||||
internal ContainerNode<T> _tail;
|
||||
private ContainerNode<T> _cache;
|
||||
private bool isEmpty;
|
||||
|
||||
public LinkedList()
|
||||
{
|
||||
_heading = new ContainerNode<T>(default(T));
|
||||
_heading = new ContainerNode<T>(null);
|
||||
isEmpty = true;
|
||||
|
||||
#if DEBUG
|
||||
Console.WriteLine("Linked list init ok");
|
||||
#endif
|
||||
}
|
||||
|
||||
public T First
|
||||
{
|
||||
get { return _first._value; }
|
||||
set
|
||||
{
|
||||
_first = new ContainerNode<T>(value);
|
||||
_heading._next = _first;
|
||||
}
|
||||
get { return _heading._next._value; }
|
||||
private set { _heading._next = value.ID; }
|
||||
}
|
||||
|
||||
public T Tail
|
||||
{
|
||||
get { return _tail._value; }
|
||||
set { _tail = new ContainerNode<T>(value); }
|
||||
get { return _heading._previous._value; }
|
||||
private set { _heading._previous = value.ID; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Add an item to the tail of linked list.
|
||||
/// </summary>
|
||||
/// <param name="t">The item ready to add to the list</param>
|
||||
public void Add(T t)
|
||||
{
|
||||
if (_first != default(ContainerNode<T>))
|
||||
//checkout if the linkedlist is null
|
||||
if (isEmpty)
|
||||
{
|
||||
First = t;
|
||||
_heading._next = t.ID;
|
||||
_heading._previous = t.ID;
|
||||
t.Next = _heading;
|
||||
t.Previous = _heading;
|
||||
isEmpty = false;
|
||||
Console.WriteLine("1st item ok");
|
||||
Console.WriteLine(_heading._next);
|
||||
Console.WriteLine(_heading._previous);
|
||||
}
|
||||
else
|
||||
{
|
||||
_cache = new ContainerNode<T>(t);
|
||||
_tail._next = _cache;
|
||||
_cache._previous = _tail;
|
||||
_tail = _cache;
|
||||
Console.WriteLine("next begin");
|
||||
t.Next = _heading;
|
||||
Console.WriteLine("step 01 ok");
|
||||
t.Previous = _heading.Previous;
|
||||
Console.WriteLine("step 02 ok");
|
||||
_heading._previous._next = t.ID;
|
||||
Console.WriteLine("step 03 ok");
|
||||
_heading._previous = t.ID;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,15 +81,18 @@ namespace StgSharp
|
||||
|
||||
public void RemoveTail()
|
||||
{
|
||||
if (_tail==default(ContainerNode<T>))
|
||||
//check out if the list has only one member
|
||||
if (Tail == First)
|
||||
{
|
||||
First = default;
|
||||
|
||||
|
||||
isEmpty = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
_cache = _tail;
|
||||
_tail = _cache._previous;
|
||||
_cache._previous = default(ContainerNode<T>);
|
||||
Tail.Previous.Next = _heading;
|
||||
Tail.Next = null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user