Bubble Sort
3
BUBBLE SORT #include <stdio.h> #include<conio.h> void main() { int array[10]; int i, j, n, temp; clrscr(); printf("Enter the number of elements\n"); scanf("%d", &n); printf("Enter the elements for bubble sort \n"); for (i = 0; i<n; i++) { scanf("%d", &array[i]); } printf("Input array is \n"); for (i = 0; i < n; i++) { printf("%d\n", array[i]); } for (i = 0; i < n; i++) { for (j = 0; j < (n - i - 1); j++) {
-
Upload
chetankapoor757 -
Category
Documents
-
view
212 -
download
0
description
bubble sorting
Transcript of Bubble Sort
![Page 1: Bubble Sort](https://reader035.fdocuments.net/reader035/viewer/2022081908/5695d0cb1a28ab9b0293e8ee/html5/thumbnails/1.jpg)
BUBBLE SORT
#include <stdio.h>
#include<conio.h>
void main()
{
int array[10];
int i, j, n, temp;
clrscr();
printf("Enter the number of elements\n");
scanf("%d", &n);
printf("Enter the elements for bubble sort \n");
for (i = 0; i<n; i++)
{
scanf("%d", &array[i]);
}
printf("Input array is \n");
for (i = 0; i < n; i++)
{
printf("%d\n", array[i]);
}
for (i = 0; i < n; i++)
{
for (j = 0; j < (n - i - 1); j++)
{
if (array[j] > array[j + 1])
{
![Page 2: Bubble Sort](https://reader035.fdocuments.net/reader035/viewer/2022081908/5695d0cb1a28ab9b0293e8ee/html5/thumbnails/2.jpg)
temp = array[j];
array[j] = array[j + 1];
array[j + 1] = temp;
}
}
}
printf("Sorted array is...\n");
for (i = 0; i < n; i++)
{
printf("%d\n", array[i]);
}
getch();
}
![Page 3: Bubble Sort](https://reader035.fdocuments.net/reader035/viewer/2022081908/5695d0cb1a28ab9b0293e8ee/html5/thumbnails/3.jpg)