コード例 #1
0
        public T RemoveFromFront()
        {
            if (IsEmpty())
            {
                throw new EmptyListException(name);
            }

            T removeItem = firstNode.Data;

            if (firstNode == lastNode)
            {
                firstNode = lastNode = null;
            }
            else
            {
                firstNode = firstNode.Next;
            }

            return(removeItem);
        }
コード例 #2
0
        public void Display()
        {
            if (IsEmpty())
            {
                Console.WriteLine($"Empty {name}");
            }
            else
            {
                Console.Write($"The {name} is: ");

                ListNode <T> current = firstNode;

                while (current != null)
                {
                    Console.Write($"{current.Data} ");
                    current = current.Next;
                }

                Console.WriteLine("\n");
            }
        }
コード例 #3
0
 public List(string listName)
 {
     name      = listName;
     firstNode = lastNode = null;
 }
コード例 #4
0
 public ListNode(T dataValue, ListNode <T> nextNode)
 {
     Data = dataValue;
     Next = nextNode;
 }