コード例 #1
0
 public bool AddToEnd(T value)
 {
     if (First != null)
     {
         var newNode = new MySinglyLinkedListNode <T>(value, First);
         Last.Next = newNode;
         Last      = newNode;
         return(true);
     }
     else if (First == null)
     {
         var newNode = new MySinglyLinkedListNode <T>(value);
         First = newNode;
         Last  = First;
         return(true);
     }
     return(false);
 }
コード例 #2
0
        public T RemoveEachGetLast(int eachN)
        {
            int num          = 1;
            var nodeToRemove = First;
            MySinglyLinkedListNode <T> previousNode = null;

            while (true)
            {
                if (num != eachN)
                {
                    previousNode = nodeToRemove;
                    nodeToRemove = nodeToRemove.Next;
                    num++;
                }
                else
                {
                    if (nodeToRemove == First)
                    {
                        First = nodeToRemove.Next;
                    }
                    if (nodeToRemove == Last)
                    {
                        Last = previousNode;
                    }

                    nodeToRemove.RemoveNodeFromList(previousNode);
                    nodeToRemove = previousNode.Next;
                    if (nodeToRemove == nodeToRemove.Next)
                    {
                        break;
                    }
                    ShowList();
                    num = 1;
                }
            }

            return(nodeToRemove.Value);
        }
コード例 #3
0
 public void RemoveNodeFromList(MySinglyLinkedListNode <T> previous)
 {
     previous.Next = Next;
 }
コード例 #4
0
 public MySinglyLinkedListNode(T value)
 {
     Value = value;
     Next  = this;
 }
コード例 #5
0
 public MySinglyLinkedListNode(T value, MySinglyLinkedListNode <T> next)
 {
     Value = value;
     Next  = next;
 }