struct st_queue{int data; struct st_queue* pnext;//pointer field};typedef struct st_queue QUEUE; void SwapNode (queue *p1, queue *p2) {queue* tmp = (queue*) malloc (sizeof (queue)); Tmp->data = p1->data; P1->data = p2->data; P2->data = Tmp->data;} queue* getend (queue* que) {if (que = null | | que->pnext = null) return que; while (que->pnext! = null) {que = que ->pnext; } return que;} Quick sort void quicksort (queue* phead, queue* pEnd) {if (NULL = = Phead | | NULL = = PEnd | | Phead = = pEnd) {return;} queue* P1 = Phead; queue* P2 = p1->pnext; int pivot = phead->data; while (P2! = Pend->pnext && P2! = NULL) {if (P2->data > Pivot) {p1 = p1->pnext; SwapNode (p1, p2);} P2 = p2->pnext; } swapnode (Phead, p1); Quicksort (Phead, p1); Quicksort (P1->pnext, pEnd);} Bubble sort void bubblesort1 (queue* que) {if (que = = NULL | | que->pnext = null) return que;//bubble sort for (queue* p1 = que; p 1! = NULL; P1 = P1->pnext) {for (queue* P2 = p1->pnext; P2! = NULL P2 = p2->pnext) {if (P1->data < P2->data) {SwapNode (P1, p2);}}} Recursive bubble sort void bubblesort2 (queue* head) {if (head = = NULL) {return;} queue* p = head->pnext; while (P! = NULL) {if (P->data > Head->data) {swapnode (Head, p);} p = p->pnext;} bubblesort2 (Head->pnext) ;}
C-Link list-quick sort, bubble sort