/***************************************************************** Sorting.cpp sorts a predifined list of numbers using the Insertion Sort Method Mark Cruz AP/IB Computer Science 2B 2/11/03 *****************************************************************/ #include #include #include #include void InsertionSort (apvector &v, int n); void SelectionSort (apvector v, int n); void Swap (int &x, int &y); int main() { apvector numbers(1); int count = 0; ifstream inFile ("Sample.txt"); ofstream outfile ("Output.txt"); inFile>>numbers[0]; while (inFile) { count++; numbers.resize(count+1); inFile>>numbers [count]; } numbers.resize(count); inFile.close(); InsertionSort(numbers, numbers.length()); for (count = 0; count0 && count % 8 == 0) outfile<< endl; } return 0; } void InsertionSort (apvector &v, int n) { int i, j; int vCurrent; for (i =1; i=0;j--) { if(v[j] <=vCurrent) break; v[j+1] = v[j]; } v[j+1] = vCurrent; } } void SelectionSort (apvector v , int n) { int i, iMax = 0; while ( /* -998 -982 -978 -971 -971 -969 -962 -961 -961 -958 -956 -950 -934 -933 -929 -911 -899 -896 -883 -882 -878 -867 -863 -860 -857 -855 -839 -837 -833 -832 -827 -827 -818 -813 -812 -795 -793 -788 -782 -777 -776 -774 -768 -755 -741 -738 -738 -731 -727 -725 -717 -715 -704 -699 -695 -692 -692 -690 -687 -687 -683 -671 -671 -671 -667 -667 -666 -663 -651 -650 -635 -617 -615 -612 -610 -609 -607 -604 -602 -596 -595 -586 -581 -579 -572 -570 -568 -564 -561 -553 -534 -533 -524 -523 -513 -509 -502 -494 -477 -477 -475 -467 -463 -458 -448 -443 -443 -435 -432 -419 -406 -395 -394 -392 -391 -388 -378 -374 -366 -351 -350 -345 -331 -311 -299 -293 -292 -291 -276 -275 -265 -256 -256 -239 -239 -239 -239 -238 -236 -231 -230 -229 -222 -218 -213 -195 -194 -191 -184 -183 -181 -181 -168 -164 -162 -140 -140 -137 -125 -118 -116 -114 -114 -114 -109 -104 -95 -92 -86 -76 -62 -60 -54 -48 -38 -32 -31 -25 -25 -15 0 3 4 8 13 17 32 39 41 45 49 75 75 81 81 81 87 89 97 107 108 120 127 135 137 139 145 155 157 166 174 175 180 187 194 204 207 216 221 223 226 231 240 245 246 247 252 253 254 256 259 262 266 267 275 275 291 294 295 295 301 305 305 310 313 314 317 334 343 345 348 349 351 352 355 357 360 367 379 381 385 397 398 403 409 424 433 437 456 462 486 487 500 504 505 509 511 515 516 524 529 534 539 539 544 554 560 563 563 566 573 580 581 585 588 588 596 608 609 615 625 642 647 652 656 660 661 669 676 677 684 691 707 708 738 748 750 755 759 775 789 796 796 798 798 804 815 823 836 842 842 842 849 853 864 865 871 881 889 896 896 899 902 913 924 937 938 956 959 961 965 968 969 970 977 984 984 992 */