Thuật toán xắp xếp
Chia sẻ bởi Phạmthanh Chúc |
Ngày 14/10/2018 |
48
Chia sẻ tài liệu: thuật toán xắp xếp thuộc Tư liệu tham khảo
Nội dung tài liệu:
Source code này minh hoạ cách dùng 5 thuật toán sắp xếp cơ bản: 1. SELECTION SORT 2. INSERTION SORT 3. BUBBLE SORT 4. QUICK SORT 5. MERGE SORT { This program demos various sorting algorithms, which includes: 1. Selection Sort 2. Insertion Sort 3. Bubble Sort 4. Quick Sort 5. Merge Sort Written by Ha Minh Nam, Hanoi, Sep 2004 } Program Sorting_Algorithm; Uses Crt; Const f_in=`INPUT.TXT`; f_out=`OUTPUT.TXT`; Var arrValue, arrTmp, arrZ:Array[0..99] of Integer; F:Text; TotalElement: Integer; {-------------------------------Begin Init---------------------------------} Procedure Init; Var i:Integer; Begin TextBackGround(LightGray); ClrScr; TextColor(Blue); For i := 2 to 79 do Begin Gotoxy(i,1); Write(chr(205)); Gotoxy(i,49); Write(chr(205)); Gotoxy(i,8); Write(Chr(205)); End; For i := 2 to 48 do Begin Gotoxy(1, i); Write(Chr(186)); Gotoxy(80, i); Write(Chr(186)); End; Gotoxy(1,1); Write(Chr(201)); Gotoxy(80,1); Write(Chr(187)); Gotoxy(1,8); Write(Chr(204)); Gotoxy(80,8); Write(Chr(185)); Gotoxy(1,49); Write(Chr(200)); Gotoxy(80,49); Write(Chr(188)); Gotoxy(20,8); Write(Chr(209)); Gotoxy(20,49); Write(Chr(207)); For i := 9 to 48 do Begin Gotoxy(20,i); Write(chr(179)); End; Gotoxy(25,2); Write(`SORTING ALGORITHMS DEMO PROGRAM`); Gotoxy(8,4); TextColor(Red); Write(`Faculty of Information Technology - Hanoi University of Technology`); Gotoxy(30,6); TextColor(Blue); Write(`Developer: Ha Minh Nam`); Gotoxy(5, 10); Write(`Algorithms:`); For i := 2 to 19 do Begin Gotoxy(i, 12); Write(Chr(196)); ENd; TextColor(Red); Gotoxy(3, 14); Write(`1. SELECTION SORT`); Gotoxy(3, 16); Write(`2. INSERTION SORT`); Gotoxy(3, 18); Write(`3. BUBBLE SORT`); Gotoxy(3, 20); Write(`4. QUICK SORT`); Gotoxy(3, 22); Write(`5. MERGE SORT`); End; {---------------------------End of Init------------------------------------} {---------------------------Begin of OutPut--------------------------------} Procedure OutPut(var max:Integer; blnMergeSort: boolean); Var i, j:Integer; Begin For i := 10 to 48 do Begin For j := 24 to 79 do Begin Gotoxy(j,i); Write(` `); End; End; Gotoxy(24, 10); Write(`- Array before sorting: `); Gotoxy(24,12); TextColor(Red); For i := 1 to max do Begin Write(arrTmp[i], ` `); End; TextColor(Blue); Gotoxy(24, 15); Write(`- Array after sorting: `); TextColor(Red); Gotoxy(24,17); If not blnMergeSort then For i := 1 to max do Begin Write(arrValue[i], ` `); End else For i := 1 to max do Begin Write(arrZ[i], ` `); End; End; {----------------------------------End of Output--------------------------} {----------------------------------Begin of SELECTION_SORT----------------} Procedure SELECTION_SORT(Var K:Array of Integer; numElement:Integer; direction:Integer); Var i,j,m, X:Integer; Begin If direction = 1 then Begin For i := 1 to numElement - 1 do Begin m := i; For j := i + 1 to numElement do If K[j
* Một số tài liệu cũ có thể bị lỗi font khi hiển thị do dùng bộ mã không phải Unikey ...
Người chia sẻ: Phạmthanh Chúc
Dung lượng: 10,07KB|
Lượt tài: 0
Loại file: zip
Nguồn : Chưa rõ
(Tài liệu chưa được thẩm định)