














Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Prepara tus exámenes
Prepara tus exámenes y mejora tus resultados gracias a la gran cantidad de recursos disponibles en Docsity
Prepara tus exámenes con los documentos que comparten otros estudiantes como tú en Docsity
Los mejores documentos en venta realizados por estudiantes que han terminado sus estudios
Estudia con lecciones y exámenes resueltos basados en los programas académicos de las mejores universidades
Responde a preguntas de exámenes reales y pon a prueba tu preparación
Consigue puntos base para descargar
Gana puntos ayudando a otros estudiantes o consíguelos activando un Plan Premium
Comunidad
Pide ayuda a la comunidad y resuelve tus dudas de estudio
Descubre las mejores universidades de tu país según los usuarios de Docsity
Ebooks gratuitos
Descarga nuestras guías gratuitas sobre técnicas de estudio, métodos para controlar la ansiedad y consejos para la tesis preparadas por los tutores de Docsity
Practica de métodos de ordenamiento en Java
Tipo: Guías, Proyectos, Investigaciones
1 / 22
Esta página no es visible en la vista previa
¡No te pierdas las partes importantes!
Desarrollo
package algoritmos.de.ordenamiento ; _/**
jlblMcaso.setText("Mejor Caso"); jlblMdcaso.setText("Caso Medio"); jlblPcaso.setText("Peor Caso"); jbtnMil.setText("1,000"); jbtnMil.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnMilActionPerformed(evt); } }); jlblA1.setText("A1"); jlblA2.setText("A2"); jlblA3.setText("A3"); jbtnDiezmil.setText("10,000"); jbtnDiezmil.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnDiezmilActionPerformed(evt); } }); jlblB1.setText("B1"); jlblB2.setText("B2"); jlblB3.setText("B3"); jbtnCienmil.setText("100,000"); jbtnCienmil.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { jbtnCienmilActionPerformed(evt); } }); jlblC1.setText("C1"); jlblC2.setText("C2"); jlblC3.setText("C3"); jbtnUnmillon.setText("1,000,000");
.addGroup(jpnlPrincipalLayout.createParallelGroup(javax.swing.GroupLa yout.Alignment.LEADING) .addGroup(jpnlPrincipalLayout.createSequentialGroup() .addComponent(jbtnCienmil) .addGap(128, 128, 128) .addComponent(jlblC1) .addGap(159, 159, 159) .addComponent(jlblC2) .addGap(130, 130, 130) .addComponent(jlblC3)) .addGroup(jpnlPrincipalLayout.createSequentialGroup() .addComponent(jbtnDiezmil) .addGap(134, 134, 134) .addComponent(jlblB1) .addGap(162, 162, 162) .addComponent(jlblB2) .addGap(127, 127, 127) .addComponent(jlblB3)) .addGroup(jpnlPrincipalLayout.createSequentialGroup() .addComponent(jbtnMil) .addGap(141, 141, 141) .addComponent(jlblA1) .addGap(160, 160, 160) .addComponent(jlblA2) .addGap(124, 124, 124) .addComponent(jlblA3)) .addGroup(jpnlPrincipalLayout.createSequentialGroup() .addComponent(jlblElementos) .addGap(92, 92, 92) .addComponent(jlblMcaso) .addGap(110, 110, 110) .addComponent(jlblMdcaso) .addGap(94, 94, 94) .addComponent(jlblPcaso)) .addGroup(jpnlPrincipalLayout.createSequentialGroup() .addComponent(jbtnUnmillon) .addGap(116, 116, 116) .addComponent(jlblD1) .addGap(160, 160, 160) .addComponent(jlblD2) .addGap(132, 132, 132) .addComponent(jlblD3))) .addContainerGap(156, Short.MAX_VALUE)))) ); jpnlPrincipalLayout.setVerticalGroup(
jpnlPrincipalLayout.createParallelGroup(javax.swing.GroupLayout.Align ment.LEADING) .addGroup(jpnlPrincipalLayout.createSequentialGroup() .addGap(23, 23, 23) .addComponent(jlblNombre) .addGap(7, 7, 7) .addGroup(jpnlPrincipalLayout.createParallelGroup(javax.swing.GroupLa yout.Alignment.BASELINE) .addComponent(jlblElementos) .addComponent(jlblMcaso) .addComponent(jlblMdcaso) .addComponent(jlblPcaso)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED ) .addComponent(jsepInt, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jpnlPrincipalLayout.createParallelGroup(javax.swing.GroupLa yout.Alignment.BASELINE) .addComponent(jbtnMil) .addComponent(jlblA1) .addComponent(jlblA2) .addComponent(jlblA3)) .addGap(11, 11, 11) .addComponent(jsepInt1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addGap(11, 11, 11) .addGroup(jpnlPrincipalLayout.createParallelGroup(javax.swing.GroupLa yout.Alignment.BASELINE) .addComponent(jbtnDiezmil) .addComponent(jlblB1) .addComponent(jlblB2) .addComponent(jlblB3)) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addComponent(jsepInt2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE) .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) .addGroup(jpnlPrincipalLayout.createParallelGroup(javax.swing.GroupLa yout.Alignment.BASELINE) .addComponent(jbtnCienmil)
pack(); } // </editor-fold> private void jbtnMilActionPerformed(java.awt.event.ActionEvent evt) { int arreglo[]= new int[1000]; double tiempob,tiempoi,tiempoq; for (int r=0;r<arreglo.length;r++){ arreglo[r]=(int)(Math.random()*1001+1); } Metodo_burbuja b = new Metodo_burbuja(); b.Burbuja(arreglo); tiempob=b.diferencia; Metodo_insercion in = new Metodo_insercion(); in.Insercion(arreglo); tiempoi=in.diferencia; Metodo_quicksort q = new Metodo_quicksort(); q.Quicksort(arreglo); tiempoq=q.diferencia; String tb = String.valueOf(String.format("%.2f",tiempob)); String.format("%.2f",tiempoi); String ti = String.valueOf(String.format("%.2f",tiempoi)); String.format("%.2f",tiempoq); String tq = String.valueOf(String.format("%.2f",tiempoq)); if (tiempob>tiempoi && tiempoi>tiempoq){ jlblA1.setText("Quicksort: "+tq+" s."); jlblA2.setText("Insercion: "+ti+" s."); jlblA3.setText("Burbuja: "+tb+" s."); } else if (tiempob>tiempoq && tiempoq>tiempoi){ jlblA1.setText("Insercion: "+ti+" s."); jlblA2.setText("Quicksort: "+tq+" s."); jlblA3.setText("Burbuja: "+tb+" s."); } else if (tiempoi>tiempob && tiempob>tiempoq){ jlblA1.setText("Quicksort: "+tq+" s."); jlblA2.setText("Burbuja: "+tb+" s."); jlblA3.setText("Insercion: "+ti+" s."); } else if (tiempoi>tiempoq && tiempoq>tiempob){ jlblA1.setText("Burbuja: "+tb+" s."); jlblA2.setText("Quicksort: "+tq+" s."); jlblA3.setText("Insercion: "+ti+" s."); } else if (tiempoq>tiempob && tiempob>tiempoi){ jlblA1.setText("Insercion: "+ti+" s."); jlblA2.setText("Burbuja: "+tb+" s."); jlblA3.setText("Quicksort: "+tq+" s."); } else if (tiempoq>tiempoi && tiempoi>tiempob){ jlblA1.setText("Burbuja: "+tb+" s."); jlblA2.setText("Insercion: "+ti+" s.");
jlblA3.setText("Quicksort: "+tq+" s."); } } private void jbtnDiezmilActionPerformed(java.awt.event.ActionEvent evt) { int arreglo[]= new int[10000]; double tiempob,tiempoi,tiempoq; for (int r=0;r<arreglo.length;r++){ arreglo[r]=(int)(Math.random()*1001+1); } Metodo_burbuja b = new Metodo_burbuja(); b.Burbuja(arreglo); tiempob=b.diferencia; Metodo_insercion in = new Metodo_insercion(); in.Insercion(arreglo); tiempoi=in.diferencia; Metodo_quicksort q = new Metodo_quicksort(); q.Quicksort(arreglo); tiempoq=q.diferencia; String tb = String.valueOf(String.format("%.2f",tiempob)); String.format("%.2f",tiempoi); String ti = String.valueOf(String.format("%.2f",tiempoi)); String.format("%.2f",tiempoq); String tq = String.valueOf(String.format("%.2f",tiempoq)); if (tiempob>tiempoi && tiempoi>tiempoq){ jlblB1.setText("Quicksort: "+tq+" s."); jlblB2.setText("Insercion: "+ti+" s."); jlblB3.setText("Burbuja: "+tb+" s."); } else if (tiempob>tiempoq && tiempoq>tiempoi){ jlblB1.setText("Insercion: "+ti+" s."); jlblB2.setText("Quicksort: "+tq+" s."); jlblB3.setText("Burbuja: "+tb+" s."); } else if (tiempoi>tiempob && tiempob>tiempoq){ jlblB1.setText("Quicksort: "+tq+" s."); jlblB2.setText("Burbuja: "+tb+" s."); jlblB3.setText("Insercion: "+ti+" s."); } else if (tiempoi>tiempoq && tiempoq>tiempob){ jlblB1.setText("Burbuja: "+tb+" s."); jlblB2.setText("Quicksort: "+tq+" s."); jlblB3.setText("Insercion: "+ti+" s."); } else if (tiempoq>tiempob && tiempob>tiempoi){ jlblB1.setText("Insercion: "+ti+" s."); jlblB2.setText("Burbuja: "+tb+" s."); jlblB3.setText("Quicksort: "+tq+" s."); } else if (tiempoq>tiempoi && tiempoi>tiempob){ jlblB1.setText("Burbuja: "+tb+" s."); jlblB2.setText("Insercion: "+ti+" s.");
jlblC3.setText("Quicksort: "+tq+" s."); } } private void jbtnUnmillonActionPerformed(java.awt.event.ActionEvent evt) { int arreglo[]= new int[1000000]; double tiempob,tiempoi,tiempoq; for (int r=0;r<arreglo.length;r++){ arreglo[r]=(int)(Math.random()*1001+1); } Metodo_burbuja b = new Metodo_burbuja(); b.Burbuja(arreglo); tiempob=b.diferencia; Metodo_insercion in = new Metodo_insercion(); in.Insercion(arreglo); tiempoi=in.diferencia; Metodo_quicksort q = new Metodo_quicksort(); q.Quicksort(arreglo); tiempoq=q.diferencia; String tb = String.valueOf(String.format("%.2f",tiempob)); String.format("%.2f",tiempoi); String ti = String.valueOf(String.format("%.2f",tiempoi)); String.format("%.2f",tiempoq); String tq = String.valueOf(String.format("%.2f",tiempoq)); if (tiempob>tiempoi && tiempoi>tiempoq){ jlblD1.setText("Quicksort: "+tq+" s."); jlblD2.setText("Insercion: "+ti+" s."); jlblD3.setText("Burbuja: "+tb+" s."); } else if (tiempob>tiempoq && tiempoq>tiempoi){ jlblD1.setText("Insercion: "+ti+" s."); jlblD2.setText("Quicksort: "+tq+" s."); jlblD3.setText("Burbuja: "+tb+" s."); } else if (tiempoi>tiempob && tiempob>tiempoq){ jlblD1.setText("Quicksort: "+tq+" s."); jlblD2.setText("Burbuja: "+tb+" s."); jlblD3.setText("Insercion: "+ti+" s."); } else if (tiempoi>tiempoq && tiempoq>tiempob){ jlblD1.setText("Burbuja: "+tb+" s."); jlblD2.setText("Quicksort: "+tq+" s."); jlblD3.setText("Insercion: "+ti+" s."); } else if (tiempoq>tiempob && tiempob>tiempoi){ jlblD1.setText("Insercion: "+ti+" s."); jlblD2.setText("Burbuja: "+tb+" s."); jlblD3.setText("Quicksort: "+tq+" s."); } else if (tiempoq>tiempoi && tiempoi>tiempob){ jlblD1.setText("Burbuja: "+tb+" s."); jlblD2.setText("Insercion: "+ti+" s.");
jlblD3.setText("Quicksort: "+tq+" s."); } } public static void main(String args[]) { _/* Set the Nimbus look and feel / //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> / If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
for (int i=1;i<array.length;i++){ if (array[i]<array[i-1]){ aux=array[i]; array[i]=array[i-1]; array[i-1]=aux; cambios= true ; } } if (cambios== false ){ break ; } } } /**Funcion que calcula el tiempo con System.nonoTime */ long fin = System.nanoTime(); double diferencia=(double)(fin-inicio) * (1.0 * Math.pow(Math.E,- 9)); }
_* To change this license header, choose License Headers in Project Properties.
_* To change this license header, choose License Headers in Project Properties.