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.