In this article you will get how to perform the bubble sorting using c++.

Bubble sorting is technique in which we compare repeatedly each adjacent elements. if they arranged in wrong order, then we swap them and arrange in an order. the first and second elements are compared and swapped if out of order.

then the second and third elements are compared and swapped if out of order. this process until the last two elements are compared and swapped if out of order

ALGORITHM:-

Step 1: Enter the length of array Step 2: Insert the elements in array Step 3: compare the first and second element Step 4: if they out of order then arrange its in order Step 5: Continues the 3 and 4 step until last two elements are swapped Step 6: Print the sorted list Step 7: Stop the Execution

PROGRAM CODE:-

#include<iostream.h> #include<conio.h> int main() { int a[50],n,i,j,temp; cout<<"Enter the size of array: "; cin>>n; cout<<"Enter the array elements: "; for(i = 0; i < n; i++) { cin>>a[i]; } for(i = 1; i < n; i++) { for(j = 0;j < (n-i); ++j) { if(a[j] > a[j+1]) { temp = a[j]; a[j] = a[j+1]; a[j+1] = temp; } } } cout<<"Array after bubble sort:"; for(i = 0; i < n; i++) { cout<<" "<< a[i]; } return 0; }

OUTPUT:-

Enter the size of array: 6 Enter the array element: 4 6 3 1 9 0 Array after bubble sort: 0 1 3 4 6 9

Bubble sorting algorithm in c++ Perform the bubble sorting in c++ Perform the bubble sorting in c How to arrange the element using bubble sorting in c++ Bubble sorting algorithm using c++

naturally like your web-site but you need to check the spelling on several of your posts. A number of them are rife with spelling problems and I find it very bothersome to tell the truth nevertheless I’ll certainly come back again.

Nice read. I just passed this onto a colleague who was doing some research on that. He just bought me lunch since I found it for him! Thus let me rephrase: Thanks for lunch!