Since a bubble sort for a linked list is not efficient, I made an example function (I had bits and pieces of code I could use for this, so there's no need for you to spend time trying to create this from scratch). I tested using 65,536 nodes with 64 bit unsigned integers for data, which took about 17.5 seconds on my system (Intel 2600K, 3.4ghz, 32 bit mode). A merge sort that uses a small (32) array of pointers to list took less than 1/32 second. The merge / array sort can sort 4,194,304 nodes in 1.2 seconds, while the bubble sort would take around 72,000 seconds, just under 20 hours, so it's not an efficient way to implement a list sort.
Code:
typedef unsigned long long UI64;
typedef struct NODE_{
struct NODE_ * next;
UI64 data;
}NODE;
NODE * SortList(NODE * pList)
{
NODE * pNew = NULL; /* sorted list */
NODE **ppCur; /* head or previous node */
NODE *pCur; /* current node */
NODE *pNxt; /* next node */
NODE *pTmp;
while(pList != NULL){ /* while list not empty */
ppCur = &pList; /* move largest to end */
while(NULL != (pNxt = (pCur = *ppCur)->next)){
if(pCur->data > pNxt->data){
pTmp = pNxt->next;
pNxt->next = pCur;
pCur->next = pTmp;
*ppCur = pNxt;
}
ppCur = &((*ppCur)->next);
}
*ppCur = NULL; /* move node to new */
pCur->next = pNew;
pNew = pCur;
}
return(pNew);
}