Bubble sorting for character array
Bubble
sorting is easy way to sort (arrange ) an array. which is either for character
or for integers.
#include
<iostream>
using
namespace std;
void
main ()
{
const char size=50;
char a[size]=
{'a','v','x','d','s','e','f','e','s','e','g','e','d','y','s','w','g','a','f','b','d','b','c','x','c'};
cout<<"The unsorted array
is";
for(int i=0;i<size-1;i++)
cout<<a[i]<<",";
cout<<"\n sorted array
is"<<endl;
for(i=0;i<size-1;i++)
{
for(int
j=0;j<size-i-1;j++)
if(a[j]>a[j+1])
{
int
temp=a[j];
a[j]=a[j+1];
a[j+1]=temp;
}
cout<<a[j]<<",";
}
}