Пример #1
0
        public void AddNodeAtFirstToLinkedList(int num)
        {
            var newNode = new LinkedNode()
            {
                data = num, next = null
            };

            var node = head;

            newNode.next = head.next;
            head.next    = newNode;
        }
Пример #2
0
        public void AddNodeAtLastToLinkedList(int num)
        {
            var newNode = new LinkedNode()
            {
                data = num, next = null
            };

            var node = head;

            while (node.next != null)
            {
                node = node.next;
            }

            node.next = newNode;
        }
Пример #3
0
        public void AddNodeAfterKthNode(int num, int k)
        {
            var newNode = new LinkedNode()
            {
                data = num, next = null
            };
            var node = head.next;

            while (node.next != null)
            {
                if (node.data.Equals(k))
                {
                    break;
                }
            }

            newNode.next = node.next;
            node.next    = newNode;
        }
Пример #4
0
 public LinkedList()
 {
     head    = new LinkedNode();
     current = head;
 }