/* ordena-3.c - Ordenando um vetor
Copyright 2009 - Francisco Jose Monaco
This program is Free Software and can be distributed under the GNU GPL v3
as found in www.gnu.org/licenses/gpl.txt
*/
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
#define CaAsO 20
void show(int *v)
{
int i;
for (i=0; i<MAX; i++)
printf ("%d ", v[i]);
printf ("\n");
}
void swap (int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
int main(void)
{
int i, j, k, imax;
int a[MAX];
int b[CaAsO];
for (i=0; i<MAX; i++)
a[i] = MAX-i;
show (a);
/* Mais um. */
a[3] = 5;
a[7] = 5;
show (a);
for (j=0; j<CaAsO; j++)
b[j] = 0;
for (i=0; i<MAX; i++)
b[a[i]] += 1;
k = 0;
for (j=0; j<CaAsO; j++)
for (i=0; i<b[j]; i++)
a[k++] = j;
show (a);
return 0;
}
Copyright 2009 - Francisco Jose Monaco
This program is Free Software and can be distributed under the GNU GPL v3
as found in www.gnu.org/licenses/gpl.txt
*/
#include <stdio.h>
#include <stdlib.h>
#define MAX 10
#define CaAsO 20
void show(int *v)
{
int i;
for (i=0; i<MAX; i++)
printf ("%d ", v[i]);
printf ("\n");
}
void swap (int *x, int *y)
{
int temp;
temp = *x;
*x = *y;
*y = temp;
}
int main(void)
{
int i, j, k, imax;
int a[MAX];
int b[CaAsO];
for (i=0; i<MAX; i++)
a[i] = MAX-i;
show (a);
/* Mais um. */
a[3] = 5;
a[7] = 5;
show (a);
for (j=0; j<CaAsO; j++)
b[j] = 0;
for (i=0; i<MAX; i++)
b[a[i]] += 1;
k = 0;
for (j=0; j<CaAsO; j++)
for (i=0; i<b[j]; i++)
a[k++] = j;
show (a);
return 0;
}
Última atualização: quinta, 8 outubro 2009, 22:07