In this post, we will write a C++ program to sort characters in ascending order by using bubble sort. we have a character array and the program will print the all the character of that array in ascending order.

C++ program to sort characters in ascending order by using bubble sort


C++ program to sort characters in ascending order by using bubble sort

#include<iostream>
#include<conio.h>

int main()
{
    system("cls");

    int i,temp,j,n;
    char a[] = "zeeshan";

    for(j=0;j<=7;j++)
        for(i=0;i<=7-j;j++)
        {
            if(a[i] > a[i+1])
            {
                temp = a[i];
                a[i] = a[i+1];
                a[i+1] = temp;
            }
        }
    for(i=0;i<=7;i++)
        std::cout<<a[i]<<"\t";

    getch();
    return 0;

}



Output

a       e       e       h       n       s       z