sorting a singly linked list with quicksort after user input and then inserting a new node and resorting list
<p>I have my code for the most part but having a rough go of it trying to get my quick sort function to work and sort through the actual link list created. Don't know if I am calling the function improperly or if I have the struct correct.</p>

<p>The program will compile and run up until it gets to the calling function for the quicksort. Then it just freezes and does nothing. Any help would be great. Thank you a head of time.</p>

<pre><code>    #include &lt;stdio.h&gt;
#include &lt;stdlib.h&gt;

struct node{
    int data;
    struct node *link_list;
};

struct node *insertion(struct node *pointer, int i){
    struct node *temp_val;
    if(pointer == NULL){
        pointer = (struct node *)malloc(sizeof(struct node));
        if(pointer == NULL){
            printf("Error Exiting\n");
            exit(0);
        }
        pointer-&gt;data = i;
        pointer-&gt;link_list = pointer;
    }else{
        temp_val = pointer;
        while(temp_val-&gt;link_list != pointer){
            temp_val = temp_val-&gt;link_list;
        }
        temp_val-&gt;link_list = (struct node *)malloc(sizeof(struct node));
        if(temp_val-&gt;link_list == NULL){
            printf("Error Exiting\n");
            exit(0);
        }
        temp_val = temp_val-&gt;link_list;
        temp_val-&gt;data = i;
        temp_val-&gt;link_list = pointer;
    }
    return(pointer);    
};


struct node *findPivot(struct node *head, struct node *term, struct node **newHead, struct node **newTerm){
    struct node *pivot = term;
    struct node *previous = NULL, *current = head, *tail = pivot;
    //finding the pivot and dividing the list while also updating the head and term
    // with newHead and newTerm
    while(current != pivot){
        if(current-&gt;data &lt; pivot-&gt;data){
            //assigning the newHead to the first value less then the pivot
            if((*newHead) == NULL){
                (*newHead) = current;
            }
            previous = current;
            current = current-&gt;link_list;
        }else{
            // if the current node has a higher value then the pivot
            // assinging it to newTerm
            if(previous){
                previous-&gt;link_list = current-&gt;link_list;
            }
            struct node *temp = current-&gt;link_list;
            current-&gt;link_list = NULL;
            tail-&gt;link_list = current;
            tail = current;
            current = temp;
        }
    }
    //Checks the case if the pivot is the smallest value and moves to head
    if((*newHead)== NULL){
        (*newHead) = pivot;
    }
    (*newTerm) = tail; // makes sure the last element is newEnd

    return pivot;

}
//finds the last node in the list and returns it
struct node *getTail(struct node *current){
    while(current != NULL &amp;&amp; current-&gt;link_list != NULL){
        current = current-&gt;link_list;
    }
    return current;
}

// the actual recursive quicksort algorithm
struct node *quickSort(struct node *head, struct node *term){
    if(!head || head == term)  //base case for the recursion
        return head;

    struct node *newHead = NULL, *newTerm = NULL;

    // the recursive case
    struct node *pivot = findPivot(head, term, &amp;newHead, &amp;newTerm);

    //no need for recursion if pivot is smallest value
    if(newHead != pivot){
        struct node *temp = newHead;
        while(temp-&gt;link_list != pivot){
            temp = temp-&gt;link_list;
        }
        temp-&gt;link_list = NULL;
        newHead = quickSort(newHead, temp);
        temp = getTail(newHead);
        temp-&gt;link_list = pivot;
    }

    pivot-&gt;link_list = quickSort(pivot-&gt;link_list, newTerm);

    return newHead;

}

void quickSortFunction(struct node **pointer){
    *pointer = quickSort(*pointer, getTail(*pointer));
    return;
}

void printList_Unsorted(struct node *pointer){
    struct node *temp;
    temp = pointer;
    printf("\nThe Data values in the list are:\n");
    if(pointer != NULL){
        do{
            printf("%d\t", temp-&gt;data);
            temp = temp-&gt;link_list;
        }while(temp != pointer);
    }else{
        printf("the list is empty\n");
    }
}


void printList_Sorted(struct node *node){
    while(node!= NULL){
        printf("%d ", node-&gt;data);
        node = node-&gt;link_list;
    }
    printf("\n");
}

int main(int argc, char *argv[]) {
    int num_nodes, node_val;
    struct node *list = NULL;
    printf("Enter the number of nodes to be created: ");
    scanf("%d", &amp;num_nodes);

    while(num_nodes --&gt; 0){
        printf("\n\nEnter the data values to be placed in a node: ");
        scanf("%d", &amp;node_val);
        list = insertion(list, node_val);
    }
    printf("\n\nThe Created list is as follow:\n");
    printList_Unsorted(list);
    printf("\n");

    quickSortFunction(&amp;list);
    printList_Sorted(list);

    //getchar();
    //getchar();



    return 0;
}
</code></pre>