unidad cuatro

32
UNIDAD IV Ing. Mario M. López Winnipeg TECNICAS ALGORITMICAS EN UNO O MAS OBJETOS DE TIPO VECTOR.

Upload: jinmaxtor

Post on 16-Dec-2015

32 views

Category:

Documents


1 download

DESCRIPTION

algoritmos

TRANSCRIPT

  • UNIDAD IVIng. Mario M. Lpez Winnipeg TECNICAS ALGORITMICAS EN UNO O MAS OBJETOS DE TIPO VECTOR.

  • Cortes de control de 2 o mas niveles.Dispersin HashSegmentacin.IntercalacinPurga.Segmentacin ordenada.Cortes de control ordenados.CONTENIDO

  • Los cortes de control en vectores se realizan cuando tenemos un vector donde cada una de sus celdas esta constituido por mas de un campo ordenado.CORTES DE CONTROL DE DOS O MAS NIVELES.

    DPTOPROVMESAVOTOSSCZCOTOCA115SCZWARNES2123CBBACERCADO1223CBBAPUNATA223CBBAPUNATA3345LPZMURILLO123

  • CORTES DE CONTROL DE DOS O MAS NIVELES.CUADRO DE VOTACION POR DEPARTAMENTODPTO PROV MESA VOTOSSCZCOTOCA115SCZWARNES2123----------------------------------------------------------------------------------------Total Dpto.138CBBACERCADO1223CBBAPUNATA223CBBAPUNATA3345--------------------------------------------------------------------------------------Total Dpto591LPZMURILLO123----------------------------------------------------------------------------------------Total Dpto.23

    CUADRO DE VOTACION POR DEPARTAMENTO Y PROVINCIADPTO PROV MESA VOTOSSCZCOTOCA115-----------------------------------------------------------Total Prov.15SCZWARNES2123------------------------------------------------------------Total Prov.123----------------------------------------------------------------------------------------Total Dpto.138CBBACERCADO1223------------------------------------------------------------ Total Prov.223CBBAPUNATA223CBBAPUNATA3345------------------------------------------------------------Total Prov.368----------------------------------------------------------------------------------------Total Dpto.591LPZMURILLO123------------------------------------------------------------Total Prov.23----------------------------------------------------------------------------------------Total Dpto.23

    DPTOPROVMESAVOTOSSCZCOTOCA115SCZWARNES2123CBBACERCADO1223CBBAPUNATA223CBBAPUNATA3345LPZMURILLO123

  • LABORATORIOCrear un archivo texto con la informacin de la votacin de los departamentos de Bolivia

  • LABORATORIOCrear la Clase CorteControl con los siguientes atributos votos array[1..100] of Tvoto, donde tvoto es un tipo de dato definido de la siguiente forma:Tvoto=record dpto : string; prov : string; mesa: integer; nro: integer;End;

  • LABORATORIO

  • LABORATORIO (crear unidad)CEMCorteControl = Class(Exception); CCorteControl = Class Private Votos: array [1..Max ] of TVoto; N : Integer; function llenarespacio(S:string;Tam:byte;tipo:char):String; Public Constructor Crear; Procedure CargarVotos(NombreArchivo:String); Procedure Mostrar(Pant:Tmemo); End;unit UCCorteControl;interfaceUses SysUtils,StdCtrls;Const max = 100;Type Tvoto = Record Dpto:string; prov:String; mesa:integer; nro: integer; End;

  • LABORATORIOimplementation function CCorteControl.llenarespacio(S:string;Tam:byte;tipo:char):String; var i:integer; begin if tipo='D' then for i:= length(s) to Tam do // Llenando espacios a la s:=s+' '; // Derecha de S if tipo='A' then for i:= length(s) to Tam do // Llenando espacios adelante s:=' '+s; // de S if tipo='C' then for i:= length(s) to Tam do if odd(i) then s:=' '+s // Llenando espacios a ambos else s:=s+' '; // lados de S llenarEspacio:=S; end;

  • LABORATORIO

    R.prov:=copy(linea,1,pos(' ',linea)-1); delete(linea,1, pos(' ',linea));

    R.mesa:=StrToInt( copy(linea,1,pos(' ',linea)-1) ); delete(linea,1, pos(' ',linea));

    R.nro:=StrToInt( copy(linea,1,pos(' ',linea)-1) ); delete(linea,1, pos(' ',linea));

    n:=n+1; votos [n]:=R; end; end; Constructor CCorteControl.Crear; begin n:=0; end;Procedure CCorteControl.CargarVotos(NombreArchivo:String); var F:TextFile; R:Tvoto; Linea:string; begin Assign(F,nombreArchivo); reset(f); while not eof(f) do begin readln(f,Linea); linea:=linea+' '; R.dpto:=copy(linea,1,pos(' ',linea)-1); delete(linea,1, pos(' ',linea));

  • LABORATORIO Procedure CCorteControl.Mostrar(Pant:Tmemo); var linea:string; i:integer; begin pant.Clear; i:=1; while i
  • LABORATORIObegin aplCorte:=ccortecontrol.crear;end;begin AplCorte.cargarvotos('C:\Users\mario lopez\Desktop\votos.txt');end;begin aplCorte.mostrar(memo1);end;Public AplCorte: CCorteContro;

  • LABORATORIObegin aplCorte.CorteUnNivel(memo1);end;

  • LABORATORIOwhile i
  • LABORATORIObegin aplcorte.CorteDosNivel(memo1);end;

  • LABORATORIO

  • DISPERSION - HASH Una tabla HASH es una estructura de datos que soporta la eliminacin, recuperacin e insercin de elementos de forma muy rpida.

    Una funcin hash es una funcin que asigna una clave a un ndice dentro del arreglo.

    Este ndice indica donde esta almacenado el elemento.

  • INSERCIONEjemplo: insertar el valor Hanson en el vector A Hash ( Valor)Hanson8

    Hanson

  • INSERCIONUltimo digito +1

  • INSERCION

  • LABORATORIO CVectorHash = Class

    Private MaxIndex : Integer; Elementos : Attay [ 1.. Max ] of String; private function hash( valor:String):Integer; Public Constructor Crear; Procedure Poner( Elemento : Integer); Function MaximoIndice : Word; Function ComoString : String; End;

  • LABORATORIOFunction CvectorHash.Crear;Begin MaxIndex:=0;End;

    Procedure CVectorHash.ComoString:String;Var i:integer; s:string; Begin s:=; For i:= 1 to maxindex do if length(elementos[ i ] )>0 then s:= s + elementos[ i ]+ , ; comostring:=s;End;

  • LABORATORIOFunction CvectorHash.Hash( Valor: String ):integer;Var letra:char; Snumero:string;Begin letra:= valor [ 2 ]; Str ( ord ( letra) , Snumero); Hash:= StrToInt( snumero [ length(Snumero) ] ); End;

    Procedure CVectorHash.Poner( Valor : String);Var ndice:integer;Begin if elementos maxindex then maxindes := idice; End;End;

  • LABORATORIOBegin Apl: CvectorHash.crear;End;

    Begin Apl.poner( edit1.text );End;

    Begin label1.caption:= apl.comostring;End;

  • SEGMENTACIONTarea por investigar

  • PURGALa purga consiste en eliminar los elementos repetidos del Vector

    112531412

    12534

  • PURGAProcedure Cvector.Purga;Var Valor,i,j: integer;Begin i:=1; While i
  • INTERCALAR

    10203040

    11022033044056

    123456

  • INTERCALARProcedure Cvector.intercala( A, B : Cvector);;Var Valor,i,j: integer;Begin i:=1 k:=0; While i
  • SEGMENTACION ORDENADATarea por investigar

  • CORTE DE COTROL ORDENADOLos cortes de control ordenados se refieren a la condicin que debe cumplir un vector para poder aplicar el algoritmo de corte de control. Caso contrario es necesario ordenar el vector de acuerdo a los niveles que se tengan que realizar los cortes de control.

  • LABORATORIOIf votos[i].dpto. > votos[i+1].dpto. then // Intercambiar registro else if votos[i].dpto.= votos[i+1].dpto. then if votos[i].prov > votos[i +1].prov then // Intercambiar Registro.

    *****************