• This is default featured slide 1 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 2 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 3 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 4 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

  • This is default featured slide 5 title

    Go to Blogger edit html and find these sentences.Now replace these sentences with your own descriptions.This theme is Bloggerized by NewBloggerThemes.com.

Mostrando entradas con la etiqueta bidimensional. Mostrar todas las entradas
Mostrando entradas con la etiqueta bidimensional. Mostrar todas las entradas

2° ejemplo

como vimos anterirormente el ejemplo anteriro es muy didactico pero es hora de ver algo mas de level entonces:::.............


//NOTA "NUNCA USAR BURBUJA"
public class arreglo{

    public static void main(String[] args) {
        int n, m, i, j;
        int empresa;
        n = 2;
        m = 12;

        empresa = (int) (Math.random() * 10 + 1);
        int arreglo[][] = new int[n + 1][m + 1];
        int temporal1[] = new int[m + 1];
        int temporal2[] = new int[m + 1];
        for (int h = 0; h < empresa; h++) {
            for (i = 0; i < n; i++) {
                for (j = 0; j < m; j++) {
                    arreglo[i][j] = (int) (Math.random() * 2000 + 1001);

                    System.out.println(arreglo[i][j]);
                }
                System.out.println("FIN DE AñO");
            }
            System.out.println("Fin de empresa ");

            for (int t = 0; t < m; t++)//Transfiere a un temporal empresa 1
            {
                temporal1[t] = arreglo[0][t];
            }
            for (int w = 0; w < m; w++)//Transfiere a un temporal empresa 2
            {
                temporal2[w] = arreglo[1][w];
            }
            quick_sort(temporal1, 0, temporal1.length - 1);
            quick_sort(temporal2, 0, temporal2.length - 1);
            System.out.println("la mayor venta en el 1° año es " + temporal1[m]);
            System.out.println("la menor venta en el 1° año " + temporal1[1]);
            System.out.println("la mayor venta en el 2° año " + temporal2[m]);
            System.out.println("la menor venta en el 2° año " + temporal2[1]);
            System.out.println();
        }
    }

//Aca esta el quick sort lo llame como metodo veran como se transfieren los datos
    public static void quick_sort(int array[], int low, int n) {
        int bajo = low;
        int alto = n;
        if (bajo >= n) {
            return;
        }
        int pivote = array[(bajo + alto) / 2];
        while (bajo < alto) {
            while (bajo < alto && array[bajo] < pivote) {
                bajo++;
            }
            while (bajo < alto && array[alto] > pivote) {
                alto--;
            }
            if (bajo < alto) {
                int T = array[bajo];
                array[bajo] = array[alto];
                array[alto] = T;
            }
        }
        if (alto < bajo) {
            int T = alto;
            alto = bajo;
            bajo = T;
        }
        quick_sort(array, low, bajo);
        quick_sort(array, bajo == low ? bajo + 1 : bajo, n);
    }
}
Personalmente yo prefiero usar este metodo que el de burbuja unos de mis motivos es la fiabilidad.
Ami me paso que a veces la burbuja me fallaba aunque este bien la logica y ademas con el tiempo y practica asumes formas mas elaboradas de programar
Share:

Visitantes

Flag Counter

Popular Posts

Etiquetas

Recent Posts