Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- int main(char** argc, int argv ) {
- /*
- * Setting up an array
- */
- int arraylen = 1024;
- int array[arraylen];
- /* Add rendom numbers to it */
- int i = 0;
- while(i < arraylen) {
- array[i] = rand() % 1024;
- i = i + 1;
- }
- /* reset i */
- i = 0;
- /* print array*/
- while(i < arraylen) {
- printf("%i: %i \n", i, array[i]);
- i = i + 1;
- }
- printf("now sorting...\n");
- /* reset i again */
- i = 0;
- /* outer loop */
- while ( i < arraylen ) {
- int j = i + 1; /* set j to i + 1 */
- int indexOfLastLow = i;
- int lastLowValue = array[i];
- /* inner loop */
- printf("---------- outer loop ------\n");
- while ( j < arraylen ) {
- printf("---------- inner loop ------\n");
- if( array[j] < lastLowValue ) {
- printf("new last low new: %i, old was: %i \n",array[j], lastLowValue);
- lastLowValue = array[j];
- indexOfLastLow = j;
- }
- j = j + 1;
- }
- /* Swaping elements */
- int tmp1 = array[i];
- int tmp2 = array[indexOfLastLow];
- array[i] = tmp2;
- array[indexOfLastLow] = tmp1;
- i = i + 1;
- }
- /* reset i */
- i = 0;
- /* print array*/
- while(i < arraylen) {
- printf("%i: %i \n", i, array[i]);
- i = i + 1;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement