0% found this document useful (0 votes)
27 views

Shivam Arora Xii-C Roll No.41

This document contains a C++ program to implement bubble sort. The program takes user input for array size and elements, calls the bubbleSort function to sort the array, and prints the sorted array. The bubbleSort function uses nested for loops to iterate through the array, swapping adjacent elements if they are out of order until the entire array is sorted. It outputs the array after each iteration to show the sorting progress.

Uploaded by

Rahul Gautam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
27 views

Shivam Arora Xii-C Roll No.41

This document contains a C++ program to implement bubble sort. The program takes user input for array size and elements, calls the bubbleSort function to sort the array, and prints the sorted array. The bubbleSort function uses nested for loops to iterate through the array, swapping adjacent elements if they are out of order until the entire array is sorted. It outputs the array after each iteration to show the sorting progress.

Uploaded by

Rahul Gautam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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