Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 4

/* PRACTICAL-9/30

Program to implement Bubble sort

*/

#include<iostream.h>
#include<conio.h>

void BubbleSort(int[],int);

//function for bubblesorting

void main()

//start of main

{
clrscr();

int AR[50],ITEM,N,Index;

//array- max. 50 elements

cout<<"\n\n How many elements do you want to create array with?


(max. 50)...";
cin>>N;

cout<<"\n\n Enter array elements...\n ";

SHIVAM ARORA

XII-C

ROLL NO.41

for (int i=0;i<N;i++)


cin>>AR[i];

BubbleSort(AR,N);

//calling statement

cout<<"\n\n The Sorted Array is as shown below...\n ";


for (i=0;i<N;i++)
cout<<AR[i]<<" ";

cout<<"\n";

getch();

//end of main

void BubbleSort(int AR[],int size)


{
int tmp,ctr=0;

for(int i=0;i<size;i++)
{
for(int j=0;j<(size-1);--i,j++)
SHIVAM ARORA

XII-C

ROLL NO.41

//function defination

{
if(AR[j]>AR[j+1])
{
tmp=AR[j];
AR[j]=AR[j+1];
AR[j+1]=tmp;
}

cout<<"\n\n Array after iteration-"<<++ctr<<"-is:";


for(int k=0;k<size;k++)
cout<<AR[k]<<" ";

cout<<"\n";
}

SHIVAM ARORA

XII-C

ROLL NO.41

***************************************************************
SHIVAM ARORA

XII-C

ROLL NO.41

You might also like