C-Single linked list-quick sort, bubble sort

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.