ordenemiento de datos
necesito ordenar un vector que contiene nombres de un grupo de estudiantes alfabeticamente...
por favor ayudeme que no se como se hace esto en C++ y necesito entregarlo urgentemente
att. liliana
por favor ayudeme que no se como se hace esto en C++ y necesito entregarlo urgentemente
att. liliana
En Internet abundan sitios donde enseñan los distintos ordenamientos.
En libros de estructuras de datos, tambien viene explicado detalladamente todo eso.
Suerte.
En libros de estructuras de datos, tambien viene explicado detalladamente todo eso.
Suerte.
Estimada Liliana : aqui va el programa que pedistes, espero que te sea util
// program StrArr.CPP
// written in Borland CPP ver 4.5
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
const int N = 5;
void Show(char **a,char *msg)
{
cout << msg;
for(int i = 0;i < N;i++)
cout << a[i] << " ";
cout << endl;
} // SHOW
void Swap(char* &a,char* &b)
{
char *holder = a;
a = b;
b = holder;
} // SWAP
void BublesSort(char *a[])
{
for(int top = 0;top < N-1;top++)
for(int i = top;i >= 0;i--)
{
if(strcmp(a[i],a[i+1]) > 0)
Swap(a[i],a[i+1]);
}
} // BUBLES SORT
int Process()
{
char *a[N] = {"father","mother","sister","brother","baby"};
Show(a,"source array : ");
BublesSort(a);
Show(a,"sorted array : ");
} // PROCESS
int main()
{
cout << "pointers : words sorting.n";
cout << "-----------------------------------------------------"
"-----------------------n";
Process();
cout << "-----------------------------------------------------"
"-----------------------n";
cout << "end of program - good bye ! ! !n";
return 0;
} // MAIN
// program StrArr.CPP
// written in Borland CPP ver 4.5
#include <conio.h>
#include <iostream.h>
#include <iomanip.h>
#include <string.h>
const int N = 5;
void Show(char **a,char *msg)
{
cout << msg;
for(int i = 0;i < N;i++)
cout << a[i] << " ";
cout << endl;
} // SHOW
void Swap(char* &a,char* &b)
{
char *holder = a;
a = b;
b = holder;
} // SWAP
void BublesSort(char *a[])
{
for(int top = 0;top < N-1;top++)
for(int i = top;i >= 0;i--)
{
if(strcmp(a[i],a[i+1]) > 0)
Swap(a[i],a[i+1]);
}
} // BUBLES SORT
int Process()
{
char *a[N] = {"father","mother","sister","brother","baby"};
Show(a,"source array : ");
BublesSort(a);
Show(a,"sorted array : ");
} // PROCESS
int main()
{
cout << "pointers : words sorting.n";
cout << "-----------------------------------------------------"
"-----------------------n";
Process();
cout << "-----------------------------------------------------"
"-----------------------n";
cout << "end of program - good bye ! ! !n";
return 0;
} // MAIN
