Hey I am a newbie in dsa so I was learning bubble sort but my output is different please see my code below
output should be: 7,12,21,70,83
my output is: 12,7,70,21,83
which is incorrect
#include <stdio.h>
void bubble_sort(int duparray[], int num) {
int temp, i, j;
for (i = 0; i < num - 1; i++) { // i means number of passes
for (j = 0; j < num - 1 - i; j++) {
if (duparray[i] > duparray[i + 1]) {
temp = duparray[i];
duparray[i] = duparray[i + 1];
duparray[i + 1] = temp;
}
}
}
for (int i = 0; i < num; i++) {
printf("%d ", duparray[i]);
}
}
void display(int duparray[], int num) {
for (int i = 0; i < num; i++) {
printf("%d ", duparray[i]);
}
}
int main() {
int array[5] = { 70, 12, 7, 83, 21 };
int n = 5;
display(array, n);
printf("\n");
bubble_sort(array, n);
// display(array, n);
return 0;
}