Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // apple xcode
- // paulogp
- /* bubble sort */
- #include <stdio.h>
- #include <stdlib.h>
- void bubble_sort (int v[], int n);
- // ordenacao por troca (bubble)
- void bubble_sort (int v[], int n)
- {
- int i, j, temp;
- for (i = n; i > 0; i--)
- {
- for (j = 1; j <= i; j++)
- {
- if (v[j - 1] > v[j])
- {
- temp = v[j - 1];
- v[j - 1] = v[j];
- v[j] = temp;
- }
- }
- printf("%i", v[i]);
- }
- }
- int main (int argc, const char * argv[])
- {
- int the_table[6] = {1, 3, 5, 4, 6, 2};
- int the_table_size = sizeof(the_table) / sizeof(int); // length of array
- printf("inicio\n");
- bubble_sort(the_table, the_table_size);
- printf("\n");
- printf("fim\n");
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement