Quick sorting by yourself

Source: Internet
Author: User

# Include <stdio. h>
# Include <malloc. h>
 
# Define Elem int
 
Typedef struct sqlist {
Elem key;
Int data;
} Sqlist;
 
Void quicksort (sqlist R [], int min, int max ){
Int I, j;
I = min;
J = max;
Sqlist temp;

If (min <max ){
Temp = R [I];
While (I! = J ){
While (I <j & temp. key <R [j]. key ){
J --;
}
If (I <j ){
R [I] = R [j];
} Www.2cto.com
While (I <j & temp. key> R [I]. key ){
I ++;
}
If (I <j ){
R [j] = R [I];
}
}
R [I] = temp;
Quicksort (R, min, I-1 );
Quicksort (R, I + 1, max );
}

}
 
 
Void main (){
Sqlist dataSort [10];
Int I = 0;
For (I = 0; I <10; I ++ ){
DataSort [I]. key = 10-I;
DataSort [I]. data = I;
}
Quicksort (dataSort, 0, 9 );
For (I = 0; I <10; I ++ ){
Printf ("key: % d data: % d \ n", dataSort [I]. key, dataSort [I]. data );
}

}
 
W397090770 Column

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.