This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void sort2(int* A, int n) | |
| { | |
| for (int i = 0; i < n; ++i) | |
| { | |
| int min = i; | |
| for (int j = i+1; j < n; ++j) | |
| { | |
| if (A[j] < A[min]) | |
| min = j; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| void sort(int* A, int n) | |
| { | |
| for (int i = 0; i < n; ++i) | |
| for (int j = i+1; j < n; ++j) | |
| if (A[j] < A[i]) | |
| { | |
| int tmp = A[i]; | |
| A[i] = A[j]; | |
| A[j] = tmp; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Overloading operator, to allow custom list of objects to be passed | |
| // eg: object obj()[, , , ]; | |
| struct list | |
| { | |
| ... | |
| list& operator,(list l); | |
| ... | |
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int binarysearch(DataType t) | |
| /* return (any) position | |
| if t in sorted x[0..n-1] or | |
| -1 if t is not present */ | |
| { | |
| int l, u, m; | |
| l = 0; | |
| u = n-1; | |
| while (l <= u) { | |
| m = (l + u) / 2; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| int* bsearch(int val, int* base, int nelems) | |
| { | |
| if (base == NULL || nelems == 0) | |
| return NULL; | |
| int lo = 0; | |
| int hi = nelems - 1; | |
| for (;;) | |
| { |
NewerOlder