INTEGRANTES DEL EQUIPO
ALEXANDER HERNANDEZ NICOLAS
JOSE ANGEL BOHORQUEZ PRUDENTE
ANDRES DIONISIO IBAÑEZ
ELIUD BOHORQUEZ

public class Radix extends JPanel implements ActionListener
{
private static final long serialVersionUID = 8865647787011721299L;

private static int q[],ql[];
int[] arr;
int n;
JTextArea sal;
JPanel bot;
JButton introducir,mostrar;


public Radix(){
setLayout(new BorderLayout());
n=6;
arr=new int[n];
interfaz();


}

public void interfaz(){
sal=new JTextArea(15,35);
sal.setBorder(BorderFactory.createTitledBorder(" ordenamiento Radix sort "));
sal.setEditable(false);

bot=new JPanel();
bot.setLayout(new GridLayout(2,0));
introducir=new JButton("Introducir");
introducir.setBackground(Color.BLACK);
introducir.setForeground(Color.WHITE);
introducir.addActionListener(this);
mostrar=new JButton("Mostrar");
mostrar.setBackground(Color.BLACK);
mostrar.setForeground(Color.WHITE);
mostrar.addActionListener(this);

bot.add(introducir);
bot.add(mostrar);

add(sal,BorderLayout.CENTER);
add(bot,BorderLayout.EAST);


}fin interfaz();

public void vector(){
for(int i=0;i<arr.length;i++){
try{
arr[i]=Integer.parseInt
(JOptionPane.showInputDialog(null,"introduce un numero","metodo radix"
,JOptionPane.INFORMATION_MESSAGE));
}catch(Exception e){
JOptionPane.showMessageDialog(null,"introduce un valor numerico"
,"Error",JOptionPane.ERROR_MESSAGE);
}
}
}
fin vector


static{
q = new int[256];
ql = new int[256];
for(int i=0;i<q.length;q[i++] = -1);
}

public static void radixSort(int[] arr){
int i,j,k,l,np[][] = new int[arr.length][2];
for(k=0;k<2;k++){
for(i=0;i<arr.length;np[i][0]=arr[i],np[i++][1]=-1)
if(q[j=((255<<(k<<3))&arr[i])>>(k<<3)]==-1)
ql[j] = q[j] = i;
else
ql[j] = np[ql[j]][1] = i;
for(l=q[i=j=0];i<q.length;q[i++]=-1)
for(l=q[i];l!=-1;l=np[l][1])
arr[j++] = np[l][0];
}
}

public static void main(String[] args){
int i;
int[] arr = new int[6];
System.out.print("original: ");
for(i=0;i<arr.length;i++){
arr[i] =Integer.parseInt
(JOptionPane.showInputDialog(null,"inserta un numero"));
System.out.print(arr[i] + " ");
}
radixSort(arr);
System.out.print("\nsorted: ");
for(i=0;i<arr.length;i++)
System.out.print(arr[i] + " ");
System.out.println("\nDone ;-)");
}



public void actionPerformed(ActionEvent ev) {
if(ev.getSource()==introducir){
sal.setText( " " );
vector();

System.out.println("fase 1");
}
if(ev.getSource()==mostrar){
sal.append("antes de ordenar:" + "\n");
for (int i=0;i < arr.length;i++){
System.out.print(arr[i]+" ");
sal.append(" " + arr[i] + " " + " " );
}

sal.append("\n"+"\n");

sal.append("despues de ordenar:" + "\n");
radixSort(arr);
for (int i=0;i < arr.length;i++){
System.out.print(arr[i]+" ");
sal.append(" " + arr[i] + " " + " " );
}
}