Ordenar un vector menor a mayor
/*! Lee un vector y luego lo muestra ordenado * *@file main.c * @date 19/03/2012 03:36:03 p.m. * @author MI Fco. Javier Rodríguez G. (fjrg76), p.avanzada@yahoo.com.mx * * Compiler: wxDev-Cpp */ #include #include #ifndefMODO_DEBUG #define MODO_DEBUG #endif #ifndef VERBOSE #define VERBOSE #endif
1
1
#define TAM_MAX
10
#if MODO_DEBUG > 0 intd_vector[TAM_MAX]={32,56,1,29,72,55,8,60,90,40}; #endif void imprime_vector(int v[], int tam) { int i; // printf("\n"); for(i=0;i 0 printf("Vector de trabajo: { "); imprime_vector(v,tam); printf(" }\n");#endif for(i=0;i 0 printf("\ni=%d ------------------------------------------------------------",i); #endif for(j=0;j 0 printf("\nComparando v[%d]=%d conv[%d]=%d",j,v[j],j+1,v[j+1]); #endif if(v[j]>v[j+1]){ tmp=v[j]; v[j]=v[j+1]; v[j+1]=tmp; #if VERBOSE > 0 printf("\t["); imprime_vector(v,tam); printf("]"); #endif } /* if(vj>vj+1) */ #ifVERBOSE > 0 else{
74: 75: 76: 77: 78: 79: 80: 81: 82: 83: 84: 85: 86: 87: 88: 89: 90: 91: 92: 93: 94: 95: 96: 97: 98: 99: 100: 101: 102: 103: 104: 105: 106: 107:108: 109: 110: 111: 112: 113: 114:
#if 0 printf("\t"); #endif } #endif } /* for(j) */ } /* for(i) */ #if VERBOSE > 0 printf("\n\nLeyendas:\n\t[...] Se realizó unintercambio\n\t No se hizo nada\n"); #endif } /* burbuja() */
int main(int argc, char *argv[]) { int vector[TAM_MAX]; int i; int tam; #if MODO_DEBUG > 0 tam=10; for(i=0;i
Regístrate para leer el documento completo.