• Save
Quick Sort
Upcoming SlideShare
Loading in...5
×
 

Like this? Share it with your network

Share

Quick Sort

on

  • 4,285 views

Metodo de ordenamiento quick sort, escrito en java, si desea descargarlo envie un mail a: ajdgeniz@hotmail.com

Metodo de ordenamiento quick sort, escrito en java, si desea descargarlo envie un mail a: ajdgeniz@hotmail.com

Statistics

Views

Total Views
4,285
Views on SlideShare
4,278
Embed Views
7

Actions

Likes
1
Downloads
0
Comments
0

2 Embeds 7

http://geniz.wordpress.com 6
http://upaep.blackboard.com 1

Accessibility

Categories

Upload Details

Uploaded via as Adobe PDF

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment

Quick Sort Document Transcript

  • 1. /*  * quickSort.java  *  * Created on 19 de julio de 2007, 19:12  *  * To change this template, choose Tools | Template Manager  * and open the template in the editor.  */ package ordenamiento; /**  *  * @author Javier  */ import java.awt.*; import javax.swing.*; import java.awt.event.*; public class quickSort extends JFrame{     int a[]=new int[5];     int i, n, j;     int max, mayor;     String salida1="", salida2="";         JTextArea areaSalida=new JTextArea(6,6);     JTextArea areaSalida2=new JTextArea(6,6);     JTextField numero=new JTextField(15);     String salida="";          public quickSort(){         super("Ordenamiento Quick Sort");                 JLabel etiqueta=new JLabel("Cuanles numeros quieres?");         JLabel etiqueta1=new JLabel("Los numeros son:");                      JButton capturar=new JButton("Capturar");         capturar.addActionListener(                 new ActionListener(){                     public void actionPerformed(ActionEvent evento){                         captura();                      }                 }         );                  JButton ordenar=new JButton("Ordenar");         ordenar.addActionListener(                 new ActionListener(){                     public void actionPerformed(ActionEvent evento){
  • 2.                         quick(a,n);                                              }                 }         );                 Container contenedor=getContentPane();         contenedor.setLayout(new FlowLayout());                 contenedor.add(etiqueta);         contenedor.add(numero);         contenedor.add(capturar);         contenedor.add(etiqueta1);         contenedor.add(areaSalida);         contenedor.add(ordenar);         contenedor.add(areaSalida2);                 setSize(300,300);         setVisible(true);     }          public void captura(){                 if (numero.getText().equals("")){            JOptionPane.showMessageDialog(null,"Escriba un nombre");            numero.setText("");        }                else{            a[i]=Integer.parseInt(numero.getText());            salida2+=a[i]+"n";            i++;            numero.setText("");                        if (i==5){                n=i;                JOptionPane.showMessageDialog(null,"Fin de la captura");                            }            areaSalida.setText(salida2);        }    }          public void muestra(int nn,int a3[]){         for(int k=0;k<nn;k++)             salida1+=a3[k]+"n";         areaSalida2.setText(salida1);     }         public void quick(int lista[], int n){       partir(0,n­1);      }     
  • 3.     public void partir(int primero,int ultimo){         int i,j,aux,central,cont=1;         i=primero;         j=ultimo;                          central=a[(primero+ultimo)/2];                          while(cont==1){         while(a[i]<central){             i++;                   }         while(a[j]>central){             j­­;                 }                  if (i<=j){                                    aux=a[i];             a[i]=a[j];             a[j]=aux;             if (i<=j)             i+=1;             if (j<ultimo)                 j+=1;                     }                 if (i>j)             cont=0;         }                          if (primero<j)             partir(primero,j);         else             if(i<ultimo)                  partir(i,ultimo);                          else                 if (primero==j)                      muestra(n,a);             }          public static void main(String[] args) {         quickSort aplicacion3 =new quickSort();         aplicacion3.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);     } }