I'm trying to create a linked list sorted by 2 different data types stored in a pointer to a tree. The structures are: 

```
typedef struct TreeNode {
   int label;
   long count;
   struct TreeNode *left;
   struct TreeNode *right;
} TreeNode;

typedef struct ListNode {
   TreeNode *ptr;
   struct ListNode *next;
   struct ListNode *prev;
} ListNode;

```

I'm using a function called addNode which sorts the linked list nodes with the following rules:

```
1. Smallest Count First
2. Smallest Label First

```

How do I correctly update my header whenever these 2 conditions aren't met? 

```
    ListNode * prev = NULL;

    while( (*head) != NULL && (*head) -> ptr -> count < new -> ptr -> count){
      prev = (*head);
      (*head) = (*head) -> next; 
    }

    while( (*head) != NULL && (*head) -> ptr -> label < new -> ptr -> label){
      prev = (*head);
      (*head) = (*head) -> next;
    }

    new -> next = (*head);  
    prev -> next = new; 
    return; 
}

```

GDB Error: 

```
Program received signal SIGSEGV, Segmentation fault.
0x0000000000400d6e in addNode (head=0x602010, new=0x602030) at list.c:84
84      prev -> next = new; 

```

Example: Each `label` contains an ASCII character and each `count` contains the frequency of that character from a string that was read in earlier. 

For the string `test` the desired list would look like:
(Key: |Label:Count| )

|10:1| -> |e:1| -> |s:1| -> |t:2| -> NULL