qualcuno mi traduce questo allegato, x favore? :quipy:
... mi servirebbe anke il main ke kiama la procedura... :quipy:
qualcuno mi traduce questo allegato, x favore? :quipy:
... mi servirebbe anke il main ke kiama la procedura... :quipy:
@@@
esiste anche il motore di ricerca: Bubble Sort
...completo:
codice:#include <stdio.h> #include <stdlib.h> int main() { int vet[10] = {2, 1, 0, 6, 9, 5, 8, 7, 3, 4}; int i, j, temp; for(i = 0; i < 10; i++) printf("%d ", vet[i]); for(i = 0; i < 9; i++) for(j = i + 1; j < 10; j++) if(vet[j] < vet[i]) { temp = vet[i]; vet[i] = vet[j]; vet[j] = temp; } printf("\n"); for(i = 0; i < 10; i++) printf("%d ", vet[i]); printf("\n"); system("pause"); return 0; }
...Terrible warlords, good warlords, and an english song
Questa è la seconda versione del Bubble. Nel caso migliore la complessità diventa n
codice:void bubblesort(int *myArray, int nr){ int i, j, limit = nr, temp; while(limit){ for(i = 0, j = 0; i < limit -1; i++){ if(*(myArray+i) > *(myArray+(i + 1))){ temp = *(myArray+i); *(myArray+i) = *(myArray+(i + 1)); *(myArray+(i + 1)) = temp; j = i+1; } } limit = j; } }
Live fast. Troll hard.
Pythonist | Djangonaut | Puppeteer | DevOps | OpenStacker | Lost in malloc
Team Lead @Gameloft Barcelona
G R A Z I E - 1 0 0 0 !!!
@@@