/* ordena-1.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);
/* Bubble sort. */
for (i=0; i<MAX-1; i++)
for (j=0; j<MAX-1-i; j++)
if (a[j]>a[j+1])
swap (&a[j], &a[j+1]);
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);
/* Bubble sort. */
for (i=0; i<MAX-1; i++)
for (j=0; j<MAX-1-i; j++)
if (a[j]>a[j+1])
swap (&a[j], &a[j+1]);
show (a);
return 0;
}
Última atualização: quinta, 8 outubro 2009, 22:05