C++ Program for Bubble sort

C++ Program for Bubble sort.

/**************************************************************	
	Author: Arun Vishnu M V
	Web: www.arunmvishnu.com
	Description: C++ Program for Bubble sort
***************************************************************/
#include<iostream.h>
#include<conio.h>
void main()
{
	int array[100],n,i,j,temp;
	clrscr();
	cout<<"How many numbers--> ";
	cin>>n;
	cout<<"Enter "<<n<<" numbers\n";
	for(i=0;i<n;i++)
		cin>>array[i];
	for(i=0;i<n;i++)
	{
		for(j=0;j<n-1;j++)
			if(array[j]>array[j+1])
			{
				temp=array[j];
				array[j]=array[j+1];
				array[j+1]=temp;
			}
	}
	cout<<"\nArray is sorted in ascending order.\n";
	for(i=0;i<n;i++)
		cout<<array[i]<<"   ";
	getch();
}

You may also like...

4 Responses

  1. sesadri roy says:

    thank u.how create this programme with using read display function.

  2. atizaz says:

    thanks for solving my problem that program is very hlpful for understanding the bubble sort

  3. lekshmi says:

    thank u so much… its a grt help for d beginners in cpp……..

  4. MGreatKanth says:

    Thanks for the Program. Its very helpful .

    Can u upload on Priority Queue ,Double Ended Queue ,Binary Search Tree ,Tree Traversal Techniques ,deleting a leaf node from binary search tree in C++ .

    Please help Me .
    Thanks in Advance

Leave a Reply

Your email address will not be published. Required fields are marked *