Insertion sort for Linked lists

This assignment consists of getting linked list and sorting it using Insertion.
I have completed the appending and printing part but having trouble to move past the sort.

This is what I have so far:

Can someone please guide me towards right direction. Thanks

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
void NumberList::InsertionSort()
{
    NumberList temp;
    ListNode *add;
    
    ListNode *addNext;
    ListNode *insert;
    
    add = head->next;
    
    while (head != nullptr/*stop when there is nothing left to sort in the original list*/)
    {
        /* Replace this comment with one line of code to assign a value to addNext */
        
        /* Replace this comment with one line of code to assign a value to insert */
        
        while( true/*stop when you are at the end of the temp list*/)
        {
            if(true/* use the  > operator to determine when to break out of this inner while loop*/)
            {
                break;
            }
            /* Replace this comment with one line of code to assign a value to insert */
        }
        /* Replace this comment with one line of code to assign a value to add->next */
        
        /* Replace this comment with one line of code to assign a value to insert->next */
        
        /* Replace this comment with one line of code to assign a value to add */
        
    }
    
    delete head;
    
    /* Replace this comment with one line of code to assign a value to head */
    
    temp.head = NULL;
    
}
Last edited on
Topic archived. No new replies allowed.