C++ Program to Implement Bubble Sort Algorithm, Exercises of Data Structures and Algorithms

A c++ program that implements the bubble sort algorithm to arrange an array of integers in ascending order. The program uses two nested for loops to compare adjacent elements and swap them if they are in the wrong order. The sorted array is then printed out using the cout statement. This document can be useful for students and lifelong learners who are studying computer science, data structures, or algorithms, as it provides a practical example of how to implement a common sorting algorithm in c++.

Typology: Exercises

2011/2012

Uploaded on 07/30/2012

dhanvantari
dhanvantari 🇮🇳

2

(2)

45 documents

1 / 1

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
#include<iostream.h>
#include<conio.h>
void main (void)
{
int a[10]={3,4,51,8,5,45,7,0,9,11};
int i,j,b;
clrscr();
for (i=0;i<=10;i++)
for (j=i+1;j<10;j++)
{
if (a[i]>=a[j])
{
b=a[i];
a[i]=a[j];
a[j]=b;
}
}
for (i=0;i<10;i++)
{
cout<<" "<<a[i];
}
getch();
}
docsity.com

Partial preview of the text

Download C++ Program to Implement Bubble Sort Algorithm and more Exercises Data Structures and Algorithms in PDF only on Docsity!

#include<iostream.h> #include<conio.h> void main (void) { int a[10]={3,4,51,8,5,45,7,0,9,11}; int i,j,b; clrscr(); for (i=0;i<=10;i++) for (j=i+1;j<10;j++) { if (a[i]>=a[j]) { b=a[i]; a[i]=a[j]; a[j]=b; } } for (i=0;i<10;i++) { cout<<" "<<a[i]; } getch(); }

docsity.com