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

BUBSORT

The document describes a bubble sort algorithm to sort elements in an array. It includes the C++ code to implement bubble sort and prompts the user to enter the number of elements and values to sort. It then displays the sorted array.

Uploaded by

ansilnassar 007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
22 views

BUBSORT

The document describes a bubble sort algorithm to sort elements in an array. It includes the C++ code to implement bubble sort and prompts the user to enter the number of elements and values to sort. It then displays the sorted array.

Uploaded by

ansilnassar 007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as RTF, PDF, TXT or read online on Scribd
You are on page 1/ 1

BUBBLE SORT IN ARRAY

Program:
//bubble sort in array
#include<iostream.h>
#include<stdlib.h>
#include<stdio.h>
void bubsort(int [],int);
int main()
{
system("cls");

int a[50],n,i,item,index;
cout<<" \n no. element u want"<<endl;
cin>>n;
cout<<"\n enter array element"<<endl;

for(i=0;i<n;i++)

cin>>a[i];
bubsort(a,n);
cout<<"\n the sorted is as shown below"<<endl;
for(i=0;i<n;i++)
cout<<a[i]<<endl;
return 0;
}
void bubsort(int a[],int size)
{
int temp,ctr=0;
for(int i=0;i<size;i++)
{
for(int j=0;j<size-1;j++)
{
if(a[j]>a[j+1])
{
temp=a[j];
a[j]=a[j+1] ;
a[j+1]=temp;
}

}
cout<<" \n array after sorting:"<<++ctr<<"-is \n";
for (int f=0;f<size;f++)
cout<<a[f]<<""<<endl;
}
}

You might also like