Пример #1
0
        public void Delete(int data)
        {
            if (Head == null)
            {
                return;
            }

            if (Head.Data == data)
            {
                Head = Head.Next;
            }

            var temp = Head;

            while (temp.Next != null)
            {
                if (temp.Next.Data == data)
                {
                    temp.Next = temp.Next.Next;
                    break;
                }

                temp = temp.Next;
            }
        }
Пример #2
0
        public virtual int?RemoveFromHead()
        {
            if (Head == null)
            {
                return(null);
            }

            var data = Head.Data;

            Head = Head.Next;

            return(data);
        }
Пример #3
0
        public void Reverse()
        {
            var current = Head;
            SingleLinkedListNode prev = null;

            while (current != null)
            {
                var next = current.Next;
                current.Next = prev;
                prev         = current;

                current = next;
            }

            Head = prev;
        }
Пример #4
0
        public void AddAtEnd(int data)
        {
            if (Head == null)
            {
                Head = new SingleLinkedListNode(data);
                return;
            }

            var temp = Head;

            while (temp.Next != null)
            {
                temp = temp.Next;
            }

            temp.Next = new SingleLinkedListNode(data);
        }
Пример #5
0
 public SingleLinkedList(SingleLinkedListNode head = null)
 {
     Head = head;
 }
Пример #6
0
        public void AddAtHead(int data)
        {
            var temp = new SingleLinkedListNode(data, Head);

            Head = temp;
        }