#include <stdio.h>
Originally Posted by
matsp
What did you actually write? Show us the code...
I'm pretty sure the algorithm for bubble-sort is correct, so you obviously had problems translating the pseudo-code into C.
--
Mats
Code:
void swap(int *a, int *b)
{
int temp = *a;
*a = *b;
*b = temp;
}
void bubbleSort(int num[])
{
for(int i = 0;; i < strlen(num); i++) // I know these lines aren't correct. (lol)
for(int j = 0; strlen(num); i++) // I know these lines aren't correct. (lol)
if(a[j-1] > a[j])
swap(a[j-1], a[j])
}
int main(void)
{
int num[8] = {7, 0, 2, 3, 5, 6, 1, 4};
for(int i = 0; i < = 7; i++)
printf("%d\n", num[i]);
getchar();
return 0;
}