Ex6_4 sorts the elements with an even value in the string from small to large, and the other elements remain unchanged.

Source: Internet
Author: User

// Sort the elements with the lower and lower mark values of string a in ascending order. Other elements remain unchanged.
# Include "stdio. H"
# Include "conio. H"
# Include "string. H"
Void main ()
{
Char A [] = "clanguage", T;
Int I, J, K;
K = strlen ();

For (I = 0; I <= K-2; I + = 2) // each round is smaller than a [I] After
{
For (j = I + 2; j <= K; j + = 2)
{
If (A [I]> A [J]) // A [I] is larger than a [J], then the switching location
{
T = A [I];
A [I] = A [J];
A [J] = T;
}
}
}
Puts ();
Printf ("/N ");
Return;

 

}

// Read the sorting idea carefully!
// If you do not want to understand it, use a few strings of numbers on the manuscript and deduct them according to the procedure.
// You can also use the program debugging method to break a breakpoint at the beginning of the loop, F5 to start debugging, and F10 to track the exchange of related numbers
// Menu bar-> View (View)-> debug windows-> Watch window, you can enter the variable value you want to observe

// For more debugging methods, see Internet

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.