1#include <stdio.h>2#include <stdlib.h>3#include <assert.h>4 5typedefstructnode{6 intdata; Storing Data7 structnode*Next ;//Next node8 }listnode;9 Ten extern intCsort (); One AListNode *root = NULL;// - - intMainintargcChar*argv[]) { the intA[] = {2,4,3, -, $, +, A};//Arranging data content -ListNode *node =NULL; -ListNode *tmp =NULL; - inti =0 ; + -Root = (ListNode *) malloc (sizeof(ListNode)); + Anode =Root; at for(i=0; i<sizeofAsizeof(int); ++i) { -printf"A in%d\n", A[i]); -TMP = (ListNode *) malloc (sizeof(ListNode)); -Tmp->data =A[i]; -Node->next =tmp; -node =tmp; in } -Tmp->next = NULL;// to + - Csort (); the *node = root->Next; $ while(node) {Panax Notoginsengprintf"Node->data%d\n", node->data); -node = node->next;// the } + A return 0;// the } + - intCsort () { $ListNode *p = root->Next; $ListNode *p_pre = p->Next; - intChange_value =0; - theassert (Root);// - Wuyi while(p) { theP_pre = p->Next; - while(p_pre) { Wu if(P->data <= p_pre->data) { - ; About}Else{ $Change_value = p->data; -P->data = p_pre->data; -P_pre->data =Change_value; - } AP_pre = p_pre->Next; + } thep = p->Next; - } $}
List sort
requirements, the data in a array is sorted from small to large, and is implemented by the Csort () function;
C-Language list sorting