jueves, 10 de noviembre de 2011

Ejecución

metodo shell####
package SimpleListShellMethod;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author Sony
*/
public class MetodoShellSimpleList {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
// TODO code application logic here
Shell Lista= new Shell();
BufferedReader entrada= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ingrese el numero de elementos que tendra la lista");
int entr= Integer.parseInt(entrada.readLine());
int contador=entr;
int numElementos=entr;
System.out.println("Ingrese los elementos");
while(contador!=0){
entr= Integer.parseInt(entrada.readLine());
Lista.InsertarElementos(entr);
contador--;
}
System.out.println("Se procedera a ordenar");
Lista.ShellExe(numElementos);
System.out.println("La lista ordenada en 'shell' es:");
Lista.Imprimir();

}
}

metodo seleccion#######
package SimpleListSelectionMethod;

import javax.swing.JOptionPane;

/**
*
* @author Sony
*/
public class Seleccion {
Nodo top;

public Seleccion(){
this.top=null;
}

public void InsertarElementos(int dato){
Nodo p= new Nodo(dato);
if(top==null){
top=p;
}
else{
Nodo aux=top;
while(aux.next!=null){
aux=aux.next;
}
aux.next=p;
}
}

public void Seleccion(int numElementos){
if(top==null){
JOptionPane.showMessageDialog(null, "No hay elementos que se puedan ordenar","Advertencia!!!",JOptionPane.WARNING_MESSAGE);
}

else{
Nodo aux=top;
Nodo aux1,aux2;
int interchange;
while(aux!=null){
aux1=aux;
aux2=aux.next;
while(aux2!=null){
if(aux1.getDato()>aux2.getDato()){
aux1=aux2;
}
aux2=aux2.next;
}
interchange= aux1.getDato();
aux1.setDato(aux.getDato());
aux.setDato(interchange);
aux=aux.next;
Imprimir();
}
}
}

public void Imprimir(){
if(top==null){
System.out.println("No existen elementos que imprimir");
}
else{
Nodo aux=top;
while(aux!=null){
System.out.print(aux.getDato()+" ");
aux=aux.next;
}
System.out.println();
}
}
}
metodo inserccion######### OJO
package simplelistinsertionmethod;

import javax.swing.JOptionPane;

/**
*
* @author DESARROLLO
*/
public class Insercion {
Nodo top;
Nodo top2;

public void Insercion(){
this.top=null;
}

public void InsertarElementos(int dato){
Nodo p= new Nodo(dato);
if(top==null){
top=p;
}
else{
Nodo aux=top;
while (aux.next!= null){
aux = aux.next;
}
aux.next = p;
}
}

public void InsercionExe(){
if(top==null){
JOptionPane.showMessageDialog(null, "No existen elementos que ordenar",
"Advertencia!!!",JOptionPane.WARNING_MESSAGE);
}
else{
Nodo aux, aux1, temp,temp1;
aux=top;
aux1=aux.next;
while(aux!=null){
if(aux!=top){
aux1=aux1.next;
temp=top;
temp1=top;
while(temp!=aux1){
if(aux.getDato()temp.getDato() && aux.getDato()aux.next.getDato()){
interchange= aux.next.getDato();
aux.next.setDato(aux.getDato());
aux.setDato(interchange);
}
aux=aux.next;
}
Imprimir();
i++;
}
endtime= System.nanoTime();
end=System.currentTimeMillis();
estimatedtime= endtime - startime;
estimated= end-star;
System.out.println(estimatedtime);
System.out.println(estimated);
}

public void Imprimir(){
if(top==null){
System.out.println("La lista esta vacia");
}
else{
Nodo aux=top;
while(aux!=null){
System.out.print(aux.getDato()+" ");
aux=aux.next;
}
System.out.println();
}
}
}

#######
#######
package SimpleListBubbleMethod;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
*
* @author DESARROLLO
*/
public class Main {

/**
* @param args the command line arguments
*/
public static void main(String[] args) throws IOException {
BurbujaSimpleList Lista= new BurbujaSimpleList();
BufferedReader entrada= new BufferedReader(new InputStreamReader(System.in));
System.out.println("Ingrese el numero de elementos que tendra la lista");
int entr= Integer.parseInt(entrada.readLine());
int contador=entr;
int numElementos=entr;
System.out.println("Ingrese los elementos");
while(contador!=0){
entr= Integer.parseInt(entrada.readLine());
Lista.InsertarElementos(entr);
contador--;
}
System.out.println("La lista es:");
Lista.Imprimir();
System.out.println("Se procedera a ordenar");
Lista.Burbuja(numElementos);
System.out.println("La lista ordenada en 'burbuja' es:");
Lista.Imprimir();
}
}

No hay comentarios:

Publicar un comentario