int ascendingSort(int* a, int n) {
int i=0, temp=0;
for (i = 0; i < n - 1; i++) {
if (a[i] > a[i + 1]) {
temp = a[i];
a[i] = a[i + 1];
a[i + 1] = temp;
i = -1;
}
}
return a;
}
void main() {
int a[] = { 1,5,9,2,3 };
int n = sizeof(a) / sizeof(int);
int result = ascendingSort(a, n);
for (int i = 0; i < n; i++) {
printf("%d", a[i]);
}
}
Im trying to Bubble sort the array in ascending order, Im not sure if the time complexity is O(n)? and if not how can I improve it?