lunes, 24 de octubre de 2016

Ordenamiento de Shell Sort

Ordenamiento de Shell Sort.
Proceso paso a paso de ordenamiento según el algoritmo de Shell.
 El ordenamiento Shell (Shell sort en inglés) es un algoritmo de ordenamiento.
El método se denomina Shell en honor de su inventor Donald Shell. 
Su implementación original, requiere O(n2) comparaciones e intercambios en el peor caso.
Código:
package start;
import java.util.Random;
public class ShellSort {
    static Random rd=new Random();
    public static void ingresar(int A[]) {
        for (int i = 0; i < A.length; i++) {
            A[i]=rd.nextInt(100);
        }
    }
    public static void mostrar(int A[]){
        for (int i = 0; i < A.length; i++) {
            System.out.print(A[i]+"  ");
        }
    }
    public static void shell(int A[]){
        int k=(A.length/2),i=0,j=0,l=0,aux;
        while(k>0){ 
            for(i=k;i=0) { 
                    l=j+k; 
                    if(A[j]<=A[l]){ 
                        j--; 
                    } 
                    else{ 
                        aux=A[j]; 
                        A[j]=A[l]; 
                        A[l]=aux; 
                        j=j-k; 
                    } 
                } 
            } 
            k=k/2; 
        } 
    }
    public static void main(String[] args) {
        int A[]=new int[9];
        ingresar(A);
        System.out.println("VEXTOR ORIGINAL");
        mostrar(A);
        shell(A);
        System.out.println("\nVECTOR ORDENADO");
        mostrar(A);
    }
}

jovenes aqui les dejo  el metodo de ordenamiento por selecion  espero que le sirva.


  







public class HelloWorld 
public void ordenamiento_por_seleccion(){
        int aux, i;
        for (i = 0; i < vect.length; i++) {
            for (int k = i+1; k < vect.length; k++) {
                if (vect[i] > vect[k]) {
                    aux = vect[i];
                    vect[i] = vect[k];
                    vect[k] = aux;
                }
COLA 

las colas tambien son llamadas FIFO (first in first out), que quiere decir el primero que entra es el primero que sale.


public class cola {
    private Object []repCola;
    private int cabCola;
    private int maxCola;
    public cola()
    {
       this.cabCola=0;
       this.maxCola=10;
       this.repCola=new Object[this.maxCola];
    }
     public cola(int mC)
    {
       this.cabCola=0;
       this.maxCola=mC;
       this.repCola=new Object[this.maxCola];
    }
    public boolean EstaLLena ()
    {
        boolean estado=false;
        if(this.cabCola>=this.maxCola)
            estado=true;
        return estado;
    
    }
    public boolean EstaVacia ()
    {
       boolean estado=false;
       if(this.maxCola==0)
           estado=true;
       return estado;
    }
    public boolean Meter(Object e)
    {
          boolean enCola =false;
          if(!this.EstaLLena())
            {
               this.repCola[this.cabCola]=new Object ();
               this.repCola[this.cabCola++]=e;
               enCola =true;
            }
     return enCola ;
    }
    public Object sacar()
    {
        Object tmpElemCola =null;
        if(!this.EstaVacia())
          {
            tmpElemCola=this.repCola[0];
            for(int i=0;i
PILAS 
son  una estructura de datos que tienendos operaciones:
push (para insertar un elemento) y pop (para extraer un elemento). su caracteristica importante es que al extraer se optiene siempre el ultimo elemento.
Ejemplo
codigo:

public class pila {
    private Object []repPila;
    private int cabPila;
    private int maxPila;
    public pila ()
    {this.cabPila=0;
     this.maxPila=10;
     this.repPila= new Object[this.maxPila];    
    }
     public pila (int mP)
    {this.cabPila=0;
     this.maxPila=mP;
     this.repPila= new Object[this.maxPila];    
    }
      public boolean EstaLLena ()
     {
        boolean estado=false ;
        if(this.cabPila>=this.maxPila)
            estado= true;
        return estado;
     }
     public boolean EstaVacia ()
     {
        boolean estado=false ;
        if(this.cabPila==0)
            estado= true;
        return estado;
     }
     
     public boolean Apilar(Object e)
     { boolean apilo=false;
      if(!this.EstaLLena())
        {
           this.repPila[this.cabPila]=new Object();
           this.repPila[this.cabPila++]=e;
           apilo =true;
        }
        return apilo;  
     }
     public Object Desapilar()
     {
         Object tempElem=null;
         if(!this.EstaVacia())
             tempElem=this.repPila[--this.cabPila];
       return tempElem;       
     }

    public Object[] getRepPila() {
        return repPila;
    }

    public int getCabPila() {
        return cabPila;
    }

    public void setRepPila(Object[] repPila) {
        this.repPila = repPila;
    }

    public void setCabPila(int cabPila) {
        this.cabPila = cabPila;
    }
     
}

domingo, 4 de septiembre de 2016

¿Que es un array?
es un conjunto de datos  almacenados siendos todos del mismo tipo, cada array(arreglo) tiene un indice q comienza en cero y termina en tamaño-1.
existen tres tipos:

Unidimencional
tambien llamado vectores, tienen un solo indices.

Bidimencionales
tambien llamadas matices, tienes dos indices  se declaran de igual manera que los vestores.

Multidimencional
se utiliza para hacer simulaciones con mas de dos dimensiones.