C single-linked list sorting

Source: Internet
Author: User

/*============================================================================ name:test.c author:vers Ion:Copyright:Your Copyright notice Description:hello World in C, Ansi-style ================================= =========================================== */#include<stdio.h>#include<stdlib.h>#defineuint8 unsigned char#defineUInt16 unsigned short#defineUInt32 unsigned inttypedefstruct{    void*Next; Uint8 Val;} mydesc_t;Staticmydesc_t *mydesc =NULL;Static voidInsert (mydesc_t *pdesc);Static voidInitdesc (void);Static voidDumpdesc (void);Static voidInitdesc (void){    inti; mydesc_t*pcur;  for(i=0;i<Ten; i++) {Pcur= (mydesc_t*)malloc(sizeof(mydesc_t)); if(pcur!=NULL) {Pcur->val =rand (); Pcur->next =NULL;        Insert (pcur); }    }}Static voidInsert (mydesc_t *Pdesc) {mydesc_t*pcur; if(mydesc==NULL) Mydesc=Pdesc; Else{pcur=Mydesc;  while(pcur->next!=NULL) Pcur= pcur->Next; Pcur->next =Pdesc; }}Static voidDumpdesc (void) {mydesc_t*pcur; Pcur=Mydesc;  while(pcur!=NULL) {printf ("dump:addr:%08x, lqi:%d \ r \ n", (unsignedint) pcur,pcur->val); Pcur= pcur->Next; }}Static voidDumplist (mydesc_t * *plist, uint8 num) {mydesc_t*pcur;    Uint8 i; printf ("dumplist:\r\n");  for(i=0; i<num;i++) {Pcur=Plist[i]; printf ("dump:addr:%08x, lqi:%d \ r \ n", (unsignedint) pcur,pcur->val); }} #include"unistd.h"Staticmydesc_t **sort_desc (mydesc_t *pdesclist, uint8 num);intMainvoid) {Srand (3);    Initdesc ();    Dumpdesc (); mydesc_t**PL = Sort_desc (Mydesc,Ten); Dumplist (PL,Ten);  Free(PL);  while(1) Sleep (1); Puts ("!!! Hello World!!!");/*Prints!!! Hello World!!! */    returnexit_success;}StaticUint8 check_descexist (mydesc_t **plist,uint8 num, mydesc_t *desc)    {Uint8 i;  for(i=0; i<num;i++)    {        if(plist[i]==desc)return 0x01; }    return 0x00;}Staticmydesc_t **sort_desc (mydesc_t *pdesclist, uint8 num) {mydesc_t**pList; mydesc_t*pcur; mydesc_t*Pmax;    Uint8 Max;    Uint8 i; printf ("sort_desc:\r\n"); PList= (mydesc_t**)malloc(sizeof(mydesc_t *) *num); if(plist!=NULL) {         for(i=0; i<num;i++) {Pcur=pdesclist; Max=0x00; Pmax=NULL;  while(pcur!=NULL) {                if(Check_descexist (plist,i,pcur) = =0x00)                {                    if(max<pcur->val) {Max= pcur->Val; Pmax=pcur; }} pcur= pcur->Next; } Plist[i]=Pmax; }    }    returnpList;}

C single-linked list sorting

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.