Linked List Sorted Insert shuts down without error

0
public void InsertSorted(K key, T data)
    {
        newNode = new Node<K, T>(key, data);
        if (head == null)
        {
            head = newNode;
            tail = newNode;
        }
        else
        {
            temp = head;
            while ((temp.NextNode != null) && temp.NextNode.data.CompareTo(newNode.data) < 0)
            {
                temp = temp.NextNode;
                temp.NextNode = tail;
            }

            newNode.PrevNode = temp;
            newNode.PrevNode.NextNode = newNode;
            if (tail.data.CompareTo(newNode.data) <0)
            {
                tail = newNode;
            }
            else
            {
                newNode.NextNode = temp.NextNode;
                newNode.NextNode.PrevNode = newNode;
            }


        }

Hello guys, today I was asked to make a linkedlist with a sorted insert method as shown above. I pushed two nodes and after the thirds node it goes through the while one time and after the curled bracket it just stop. No error, no exception the program just shuts down. Can someone help with fixing my code so this works or at least tell me why I get this error?

The exit code is the following: The program '[12812] LinkedList.exe' has exited with code -2147023895 (0x800703e9).

Thanks for any help, Mika.

c#
linked-list
asked on Stack Overflow Apr 28, 2017 by Mreifenberger

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0