Created
September 26, 2012 14:08
-
-
Save poying/3788268 to your computer and use it in GitHub Desktop.
3.27
This file contains 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
#include <stdio.h> | |
#define SIZE 10 | |
#define ANS 2 | |
int in(int i, const int *h){ | |
int c = SIZE; | |
while(c--){ | |
//printf("> %d\n", *h); | |
if(*h == i){ | |
return 1; | |
} | |
h++; | |
} | |
return 0; | |
} | |
void sort(int *h, int size){ | |
int counter = 0, i, tmp, index; | |
while(size - counter){ | |
for(i = counter; i > 0; i--){ | |
if(h[i] > h[i-1]){ | |
//printf("$ %d\t%d\t%d\n", i, h[i], h[i-1]); | |
tmp = h[i-1]; | |
h[i-1] = h[i]; | |
h[i] = tmp; | |
}else{ | |
break; | |
} | |
} | |
//printf("====\n"); | |
counter++; | |
} | |
} | |
int main(void){ | |
int input, history[SIZE] = {0}, tmp, counter = SIZE; | |
while(counter--){ | |
printf(" %d\n> ", SIZE - counter); | |
scanf("%d", &input); | |
if(in(input, history)){ | |
counter++; | |
}else{ | |
history[SIZE - counter - 1] = input; | |
} | |
} | |
printf("\nBefore Sort \n------------\n"); | |
for(tmp = 0; tmp < SIZE; tmp++){ | |
printf("%d\n", history[tmp]); | |
} | |
sort(history, SIZE); | |
printf("\nAfter Sort \n------------\n"); | |
for(tmp = 0; tmp < SIZE; tmp++){ | |
printf("%d\n", history[tmp]); | |
} | |
printf("==================\n"); | |
for(tmp = 0; tmp < ANS; tmp++){ | |
printf("%d\n", history[tmp]); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment