双链表排序算法
本文提供一种双链表排序方法,主要思路是:双链表的next,prev 指针不变,即链表的前后关系不变,只交换链表中的数据内容;如升序排序,从开始向后两两比较,若前面A比后面大B,交换AB的内容,保证了是升序,但不能保证B比A前面的内容小,所以要向前遍历,发现前面的比后面的大,交换数据;这样向后一次遍历完成,排序完成;
这样做的好处是:比网上交换指针的那种算法简单,思路清晰;
cJSON 是C语言处理 json的方法(cJSON.c和cJSON.h两个文件),具体用法可百度;
cJSON 组的数据其实就是一个双链表,所以用cJSON组json的数据作为双链表的数据(这样不用自己写双链表了);
cJSON 的节点数据:
/* cJSON Types: */
#define cJSON_False 0
#define cJSON_True 1
#define cJSON_NULL 2
#define cJSON_Number 3
#define cJSON_String 4
#define cJSON_Array 5
#define cJSON_Object 6
typedef struct cJSON {
struct cJSON *next,*prev;
struct cJSON *child; /* An array or object item will have a child pointer pointing to a chain of the items in the array/object. */
int type; /* The type of the item, as above. */
char *valuestring; /* The item's string, if type==cJSON_String */
int valueint; /* The item's number, if type==cJSON_Number */
double valuedouble; /* The item's number, if type==cJSON_Number */
char *string; /* The item's name string, if this item is the chi