letras ordenadas

akane
22 de Marzo del 2005
como hacer que le porgrama ordendee las letras dadas ´por el usuario

noel solw
22 de Marzo del 2005
// program CharSort.cpp
// bubble sort of chars array.
// 22/3/2005
// written in Borland CPP ver 5.5

#include <iostream.h>
#include <iomanip.h>
#include <string.h>
#include <stdio.h>

const int MAX = 240;

char *GetString()
{
char a[MAX];
cout << "get a string of letters --> ";
gets(a);
cout << endl;
return a;
} // GET STRING

void Swap(char &a,char &b)
{
char c = a;
a = b;
b = c;
} // SWAPS CHARS

void BubbleSort(char *a)
{
int max = strlen(a);
for(int top = 0; top < max-1; top++)
{
for(int i = top; i >= 0; i--)
{
if (a[i] > a[i+1])
Swap(a[i],a[i+1]);
else
break;
}
}
} // BUBBLE SORT

void Show(char *a,char *msg)
{
cout << msg << a << endl;
} // SHOW

int main()
{
char *a = GetString();
Show(a,"source string : ");
BubbleSort(a);
Show(a,"sorted string : ");
cout << endl << "end of program - good bye ! ! !n";
return 0;
} // MAIN