/*
 * Main.java
 *
 * Created on 13 de Janeiro de 2006, 09:40
 *
 * To change this template, choose Tools | Options and locate the template under
 * the Source Creation and Management node. Right-click the template and choose
 * Open. You can then make changes to the template in the Source Editor.
 */

package estruturasdedados;

/**
 *
 * @author Alexandre
 */

import java.util.*;

public class Main {
    
    /** Creates a new instance of Main */
    public Main() {
    }
    
    /**
     * @param args the command line arguments
     */
    
    // Declara um vetor de modo global
    public static int iVetor[] = new int[ 100 ];
    // Declara uma matriz de modo glogal
    public static char cMatriz[][] = new char[ 100 ][ 80 ];
    
    /**
    *
    * @author Alexandre
    * @param Duas posicoes do vetor para que seja realizado a troca entre elas
    * @funcao Utilizado para trocar duas posicoes no vetor
    */
    public static void VetorTroca( int Pos1, int Pos2 )
    {
        int Aux = iVetor[ Pos1 ];
        iVetor[ Pos1 ] = iVetor[ Pos2 ];
        iVetor[ Pos2 ] = Aux;
    }
    
    public static void SeparaPartes( String Mensagem )
    {
        StringTokenizer Frases = new StringTokenizer( Mensagem, ";");
        boolean PossuiElementos = false;
        
        while( Frases.hasMoreElements())
        {
            System.out.println( Frases.nextElement());
            PossuiElementos = true;
        }
        
    }
    /**
    * @param args the command line arguments
    */
    public static void main(String[] args) {
        
        
        // Entrada via parametrizacao
        for( int N = 0; N < args.length; N ++ )
        {
            System.out.println("Voce passou o " + N + " argumento: " + args[ N ]);
            // Caso gostaria de transformar o valor de entrada em numero poderia:
            // int iValor = Integer.parseInt( args[ 0 ] );
        }
        
        // Gera números aleatorios para o vetor
        for( int N = 0; N < 100; N ++ )
        {
            iVetor[ N ] = (int)(Math.random()* 100);
        }
        
        // Ordenação dos dados usando bubble sort II
        boolean bTrocou = true;
        while( bTrocou )
        {
            bTrocou = false;
            for( int N = 0; N < 99; N ++ )
            {
                if( iVetor[ N ] > iVetor[ N + 1 ])
                {
                    VetorTroca( N, N + 1 );
                    bTrocou = true;
                }
            }
        }
        
        // Impressão dos dados já ordenados
        for( int N = 0; N < 100; N ++ )
        {
            System.out.println( iVetor[ N ] );
        }
        
        // Trabalho com Matriz
        for( int N = 0; N < 100; N ++ )
        {
            for( int Y = 0; Y < 80; Y ++ )
            {
               cMatriz[ N ][ Y ] = (char)(int)(Math.random()* 255);
            }
        }
        
        for( int N = 0; N < 100; N ++ )
        {
            for( int Y = 0; Y < 80; Y ++ )
            {
               System.out.print( cMatriz[ N ][ Y ] );
            }
            System.out.println();
        }        
        
        // Listas Encadeadas
        LinkedList Lista = new LinkedList();
        
        Lista.add("Juca da Silva");
        Lista.add("Marieta Morena");
        Lista.add("Camila Marmota");
        
        
        if( Lista.contains("Juca da Silva"))
        {
            System.out.println( "Sim, a Lista tem ele");
        }
        else
        {
            System.out.println( "nao, a Lista tem ele");
        }
        
        
        // Ordena a lista
        Collections.sort( Lista );
        
        int N = 0;
        while( Lista.size() > N )
        {
            System.out.println( "Na Lista tem:" + Lista.get(N));
            N ++;
        }

        Collections.reverse( Lista );
        
        N = 0;
        while( Lista.size() > N )
        {
            System.out.println( "Na Lista tem:" + Lista.get(N));
            N ++;
        }
        
        System.out.println( "Juca esta na posicao:" + Lista.indexOf("Juca da Silva"));
        
        System.out.println( Lista );
        
        while( Lista.size() > 0 )
        {
            System.out.println( "Removendo : " + Lista.remove(0));
        }
        
        
        // Separacao de Tokens
        SeparaPartes("A vaca;O boi;A bananeira");
    }
}