C language/MFC selection and sorting

Source: Internet
Author: User
The purpose of this article is to understand the selection and sorting in C language, and implement selection and sorting in C and MFC respectively. For the line feed of EditControl in MFC, use the following method: sort_resultsort_result + _ T (~ \ R \ n); in addition to \ r \ n, you must also set the CEdit attribute: AutoHScroll to False and MultiLine.

The purpose of this article is to understand the selection and sorting in C language, and implement selection and sorting in C and MFC respectively.

The program implementation in MFC is as follows:

Char tmp [10] = ""; int rand_num [10]; CString str [10]; CString result; CString sort_result; void CNM_MFCDlg: OnBnClickedOk () {CEdit * pBoxOne; pBoxOne = (CEdit *) GetDlgItem (IDC_EDIT1); srand (unsigned) time (NULL); for (int x = 0; x <10; x ++) {rand_num [x] = rand () % 100; str [x] = itoa (rand_num [x], tmp, 10 ); result = result + str [x] + _ T ("");} pBoxOne-> SetWindowText (result); // MessageBox (str, _ T ("program running result "), MB_ OK); result. R EleaseBuffer ();} void CNM_MFCDlg: OnBnClickedButton1 () {CEdit * pBoxTwo; pBoxTwo = (CEdit *) GetDlgItem (IDC_EDIT2); selection_sort (rand_num, 10 ); for (int x = 0; x <10; x ++) {str [x] = itoa (rand_num [x], tmp, 10 ); sort_result = sort_result + str [x] + _ T ("");} sort_result = sort_result + _ T ("~ \ R \ n "); // UpdateData (false); pBoxTwo-> SetWindowText (sort_result); sort_result.ReleaseBuffer ();} void CNM_MFCDlg: OnBnClickedCancel () {cdigealox :: onCancel ();} void selection_sort (int * a, int n) {int I, j, s; for (I = 0; I
 
  
The program running result is as follows:
  

The function of selecting a sorting algorithm is as follows:

/* Sort by the selected sorting method: from small to large; void selection_sort (int * a, int n) parameter: int * a: Array name int n: number of sorting elements */void selection_sort (int * a, int n) {int I, j, s; for (I = 0; I
   
    
You can use the following method to wrap Edit Control in MFC:
    

sort_result = sort_result + _T("~ \r\n");

In addition to \ r \ n, you must set the attributes of CEdit:

Set Auto HScroll to False, MultiLine to True, and Want Return to True.

This article is available at http://www.nowamagic.net/librarys/veda/detail.

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.