-
Notifications
You must be signed in to change notification settings - Fork 0
/
bubble_sort.c
42 lines (41 loc) · 953 Bytes
/
bubble_sort.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <stdio.h>
int bubble_sor(int arr[], int size);
int main()
{
int size;
printf("Enter the size of an Array: ");
scanf("%d", &size);
int arr[size];
printf("Enter the Elements of an Array: ");
for (int i = 0; i < size; i++)
{
scanf("%d", &arr[i]);
}
bubble_sor(arr, size);
// printf("The sorted array is: %d", bubble_sor);
return 0;
}
int bubble_sor(int arr[], int size)
{
int i, j, temp;
for (i = 0; i < size; i++)printf(" %d ", arr[j]);
printf("\n");
printf("The sorted array is as: %d\n", arr[i]);
{
for (j = 0; j < size - 1 - i; j++)
{
if (arr[j] > arr[j + 1])
{
temp = arr[j];
arr[j] = arr[j + 1];
arr[j + 1] = temp;
}
}
}
printf("The sorted array is as: \n");
for (i = 0; i < size; i++)
{
printf("%d ", arr[i]);
}
printf("\n");
}