Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
‐ ESCRIBIR UNA APLICACIÓN QUE PERMITA CREAR UNA LISTA SIEMPRE ORDENADA
DE FORMA ASCENDENTE Y MOSTRAR LOS DATOS. ADEMAS PASAR A OTRA LISTA LOS SUELDOS
MAYORES A 1000 BS.
CLASE PROCESO DE ORDENACION
import javax.swing.*;
class PROCESO_ORDENACION {
EMPLEADO ingreso (EMPLEADO p, EMPLEADO u)
{ String op;
int sw=0;
do {
if(p==null)
{
p= new EMPLEADO();
p.nom=JOptionPane.showInputDialog("Ingrese Nombre ‐‐‐‐‐‐>");
p.prof=JOptionPane.showInputDialog("Ingrese Profesion ‐‐‐>");
p.sue=Integer.parseInt(JOptionPane.showInputDialog("Ingrese Sueldo
‐‐>"));
p.sig=null;
}
else
{
sw=0;
u= new EMPLEADO();
u.nom=JOptionPane.showInputDialog("Ingrese Nombre ‐‐‐‐‐‐>");
u.prof=JOptionPane.showInputDialog("Ingrese Profesion ‐‐‐>");
u.sue=Integer.parseInt(JOptionPane.showInputDialog("Ingrese Sueldo
‐‐‐>"));
// PROCESO DE BUSCAR LA POSICION DEL NOMBRE
EMPLEADO a,x;
x=p;
a=p;
while(x!=null)
{
if (x.nom.compareTo(u.nom)>0)
{ sw=1;
if (p==x)
{
u.sig=p;
p=u;
}
else
{
a.sig=u;
u.sig=x;
}
}
a=x;
x=x.sig;
}
if (sw==0)
{
u.sig=null;
a.sig=u;
}
}
op=JOptionPane.showInputDialog(" Para Salir escriva FIN ");
}
while (op.compareTo("FIN")!=0);
return (p);
}
void ver (EMPLEADO x)
{ String cad="";
while (x!=null)
{
cad=cad+"\n NOMBRE = "+x.nom+"\n PROFESION = "+x.prof+"\n SUELDO = "+x.sue+"\n‐
‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐\n";
x=x.sig;
}
JOptionPane.showConfirmDialog(null,cad);
}
void pasar_a_otra_lista (EMPLEADO p)
{
EMPLEADO pri,ult,x;
String cad="";
pri=p;
ult=p;
x=p;
while(x!=null)
{
if (x.sue>1000)
{
if (x==p)
{
pri=new EMPLEADO();
pri.nom=x.nom;
pri.prof=x.prof;
pri.sue=x.sue;
pri.sig=null;
}
else
{
ult=new EMPLEADO();
ult.nom=x.nom;
ult.prof=x.prof;
ult.sue=x.sue;
ult.sig=pri;
pri=ult;
}
}
x=x.sig;
}
//* VER LA NUEVA LISTA
x=pri;
while(x!=null)
{
cad=cad+"SUELDOS MAYORES A 1000\n NOMBRE = "+x.nom+"\n
PROFESION = "+x.prof+"\n SUELDO = "+x.sue+"\n‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐‐\n";
x=x.sig;
}
JOptionPane.showMessageDialog(null,cad);
}
}
CLASE PRINCIPAL
LISTAS_ORDENADAS_POR_INSERCION
import javax.swing.*;
public class LISTAS_ORDENADAS_POR_INSERCION {
public static void main(String[] args) {
String op;
EMPLEADO p=null,u=null;
PROCESO_ORDENACION pro=new PROCESO_ORDENACION();
do{
op=JOptionPane.showInputDialog(" M E N U \n 1.‐ INGRESAR DATOS \n 2.‐
VER DATOS \n 3.‐ PASAR A OTRA LISTA \n 4.‐ SALIR \n ELEGIR OPCION ‐> ");
switch (op.charAt(0))
{
case '1':p=pro.ingreso(p,u); break;
case '2':pro.ver(p);break;
case '3':pro.pasar_a_otra_lista(p);break;
}
}
while (op.charAt(0)!='4');
}
}
CLASE EMPLEADO
class EMPLEADO {
String nom,prof;
float sue;
EMPLEADO sig;
}