它出什么问题了?它应该按升序对其进行排序。它不会导致程序崩溃,但是当我很确定有什么问题时,因为当我将链接列表链接到其他函数时,它会陷入无限循环。
#include <stdio.h>
#include <stdlib.h>
struct dataTag {
int key;
};
struct nodeTag {
struct dataTag data;
struct nodeTag *pNext;
};
typedef struct dataTag dataStructType;
typedef struct nodeTag nodeStructType;
nodeStructType *SortList(nodeStructType *pFirst)
{
nodeStructType *swap,*ptr;
if(pFirst == NULL)
return NULL;
else
{
swap = pFirst;
ptr = pFirst -> pNext;
while(ptr != NULL)
{
if(ptr -> data.key < swap -> data.key)
swap = ptr;
ptr = ptr -> pNext;
}
swap -> pNext = SortList(pFirst -> pNext);
return swap;
}
}
int main(void)
{
nodeStructType *pFirst;
/* Lets say codes exists here that makes a link list etc just to make the code short*/
pFirst = SortList(pFirst);
/*Free List*/
return 0;
}