Пример #1
0
        public string RemoveFromBack()
        {
            if (IsEmpty())
            {
                throw new EmptyListException(name);
            }

            string removeItem = lastNode.Data;

            if (firstNode == lastNode)
            {
                firstNode = lastNode = null;
            }
            else
            {
                ListNodeString current = firstNode;

                while (current.Next != lastNode)
                {
                    current = current.Next;
                }

                lastNode     = current;
                current.Next = null;
            }

            return(removeItem);
        }
Пример #2
0
 public void InsertAtBack(string insertItem)
 {
     if (IsEmpty())
     {
         firstNode = lastNode = new ListNodeString(insertItem);
     }
     else
     {
         lastNode = lastNode.Next = new ListNodeString(insertItem);
     }
 }
Пример #3
0
 public void InsertAtFront(string insertItem)
 {
     if (IsEmpty())
     {
         firstNode = lastNode = new ListNodeString(insertItem);
     }
     else
     {
         firstNode = new ListNodeString(insertItem, firstNode);
     }
 }
Пример #4
0
        public string RemoveFromFront()
        {
            if (IsEmpty())
            {
                throw new EmptyListException(name);
            }

            string removeItem = firstNode.Data;

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

            return(removeItem);
        }
Пример #5
0
        public void Display()
        {
            if (IsEmpty())
            {
                Console.WriteLine($"Empty {name}");
            }
            else
            {
                Console.Write($"The {name} is: ");

                ListNodeString current = firstNode;

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

                Console.WriteLine("\n");
            }
        }
Пример #6
0
 public ListString(string listName)
 {
     name      = listName;
     firstNode = lastNode = null;
 }