Enter n strings, sort, and then output from small to large

Source: Internet
Author: User

/******************************************************************************************* * * Function Name: CompareString () * * Author: ZYH * * Version: 1.0.0 * * Date: 2011-6-20 * * Function Description: Input n strings, from small to large output * * The function called by this function list: * * Call the Function list: * * is Table Accessed: * * Modified TABLE: * * input: *string_array_in[]---input array int total---array elements * * output: char *string_array_out[]---output array * * Return value: no * * Other: * * Modified History: 1. Modified: Modified By: Version: revised brief: 2. ***************************************************** /void CompareString (char *string_array_in[], char *string_array_out[], int Total)/* is essentially the choice of sorting method */{int liv_i;////* element lookup, compare wheel number, n elements compare N-1 round/int liv_j; * I elements compare n-1-i times/int small;/* Select Sort method, Store min The subscript of the element */char *temp; /* Swap TEMP variable * for (liv_i = 0; liv_i < total-1; liv_i++) {small = liv_i; for (liv_j = liv_i+1; liv_j < total; liv_j+ +) {if (strcmp (String_array_in[liv_j],string_array_in[small]) <0)/* Cannot use if (String_array_in[liv_j] < String_arra Y_in[small]) */{small = LIv_j; } if (small!= liv_i) {temp = String_array_in[small]; String_array_in[small] = string_array_in[liv_i]; string_array_in[ Liv_i] = temp; (liv_i = 0; liv_i < total; liv_i++) {string_array_out[liv_i] = string_array_in[liv_i];}

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.