Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #ifndef DEBUG
- #define DEBUG(...) printf(__VA_ARGS__)
- #endif
- void bubble_sort(int a[], int br[]){
- int i, j, tmp;
- for(i = 1; i <= 10; i++){
- for(j = 2; j <= 10; j++){
- if(a[j-1] < a[j]){
- tmp = a[j-1];
- a[j-1] = a[j];
- a[j] = tmp;
- tmp = br[j-1];
- br[j-1] = br[j];
- br[j] = tmp;
- }
- }
- }
- for(i = 1; i <= 10; i++){
- if(a[i] == 0) continue;
- printf("%d\t", br[i]);
- }
- printf("\n");
- for(i = 1; i <= 10; i++){
- if(a[i] == 0) continue;
- printf("%d\t", a[i]);
- }
- }
- /*void selection_sort(int a[], int br[]){
- int i, j, max, tmp, n=10;
- for(i = 1; i <= n - 1; i++){
- max = i;
- for(j = i + 1; j <=n; j++){
- if(a[j] > max){
- max = j;
- }
- }
- tmp = a[max];
- a[max] = a[i];
- a[i] = tmp;
- tmp = br[max];
- br[max] = br[i];
- br[i] = tmp;
- }
- for(i = 1; i <= 10; i++){
- printf("%d ", a[i]);
- }
- printf("\n");
- for(i = 1; i <= 10; i++){
- printf("%d ", br[i]);
- }
- }*/
- void bucket_sort(int in[], int out[], int n){
- int i, br[10]={0};
- for(i = 1; i <= n; i++){
- out[in[i]]++;
- }
- for(i = 1; i <= 10; i++){
- br[i]= i;
- }
- /*for(i = 1; i <= 10; i++){
- printf("%d ",br[i]);
- }
- printf("\n");
- for(i = 1; i <= 10; i++){
- printf("%d ",out[i]);
- }*/
- //selection_sort(out, br);
- bubble_sort(out, br);
- }
- int main() {
- int polje[1000], out[1000]={0}, i=1, counter=0;
- while(1){
- scanf("%d", &polje[i]);
- if(polje[i]==0)break;
- i++;
- counter++;
- }
- /*for(i = 1; i <=counter; i++){
- printf("%d ", polje[i]);
- }*/
- bucket_sort(polje, out, counter);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement