Experiment 12: Program To Implement Bubble Sorting: Algorithm
Experiment 12: Program To Implement Bubble Sorting: Algorithm
Experiment 12: Program To Implement Bubble Sorting: Algorithm
sorting
Algorithm
1. Input array
2. BubbleSort()
2.1 for i=0 till i<size, i++
for j=0 till j<size-1, j++
if AR[j]>AR[j+1]
tmp=AR[j]
AR[j]=AR[j+1]
AR[j+1]=tmp;
print array
Program
#include<stdio.h>
#include<conio.h>
void BubbleSort(int[],int);
void main()
{
int AR[50],ITEM,N,index,i;
clrscr();
printf("\n\n How many elements do you want to add ");
scanf("%d",&N);
printf("\n Enter Array elements ");
for(i=0;i<N;i++)
{
scanf("%d",&AR[i]);
}
BubbleSort(AR,N);
printf("\n\n The sorted array is ");
for(i=0;i<N;i++)
{
printf("\t%d",AR[i]);
}
getch();
}
#include<stdio.h>
#include<conio.h>
int Lsearch(int[],int,int);
void main()
{
int AR[50],ITEM,N,index,i;
clrscr();
printf("\n\n Enter no of elements ");
scanf("%d",&N);
printf("\n Enter Array Elements ");
for(i=0;i<N;i++)
{
scanf("%d",&AR[i]);
}
printf("\n Enter element to be searched ");
scanf("%d",&ITEM);
index=Lsearch(AR,N,ITEM);
if(index==-1)
printf("\n Element not found ");
else
printf("\n\n Element found at Position: %d ",index+1);
getch();
}
Program
#include <stdio.h>
#include <conio.h>
#define size 100
int partition(int a[], int beg, int end);
void quick_sort(int a[], int beg, int end);
void main()
{
int arr[size], i, n;
printf("\n Enter number of elements ");
scanf("%d", &n);
printf("\n Enter the elements of the array ");
for(i=0;i<n;i++)
{
scanf("%d", &arr[i]);
}
quick_sort(arr, 0, n-1);
printf("\n The sorted array is: ");
for(i=0;i<n;i++)
printf(" %d\t", arr[i]);
getch();
}