-
Notifications
You must be signed in to change notification settings - Fork 1
/
Bubble_Sort.c
61 lines (60 loc) · 1.49 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/**********************************************************************************************
* File : Bubble_Sort.c
* Program : Program to implement Bubble Sort on an array of numbers
* Language : C
* Author : Tom Sibu
* Version : 1.0
* Date : 12/11/2023
***********************************************************************************************/
#include <stdio.h>
void main() {
int n,i,j,small=0,temp=0,count=0;
count+=3;
printf("Enter the number of entries : ");
scanf("%d",&n);
int arr[n];
printf("Enter %d numbers : \n",n);
count++;
for (i=0;i<n;i++) {
count++;
scanf("%d",&arr[i]);
Count++;
}
count++;
printf("Unsorted Array :");
for (i=0;i<n;i++) {
count++;
printf(" %d",arr[i]);
count++;
}
count++;
printf("\n");
//Bubble Sort
for (i=0;i<n-1;i++) {
count++;
for (j=i+1;j<n;j++) {
count++;
if (arr[i]>arr[j]) {
count++;
temp=arr[i];
arr[i]=arr[j];
arr[j]=temp;
count+=3;
}
}
count++;
}
count++;
printf("Sorted Array using Bubble Sort :");
for (i=0;i<n;i++) {
count++;
printf(" %d",arr[i]);
count++;
}
count++;
printf("\n");
//Time Complexity & Space Complexity
count+=2;
printf("Time Complexity of program : %d\n",count);
printf("Space Complexity of program : %d\n",24+4*n);
}