Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- (*-------------------------- S H E L L S O R T(METODO SHELL) DECRECIENTE ---------------------*)
- Procedure ShellSortDrececiente(Var X : TVEmpleados; N: Integer);
- Var
- Done: Boolean;
- Jump,I,J: Integer;
- Begin
- Jump := N;
- While (Jump > 1) Do
- Begin
- Jump := Jump Div 2;
- Repeat
- Done := true;
- For J := 1 To (N - Jump) Do
- Begin
- I := J + Jump;
- //AGREGAR LOS CAMPOS DEL REGISTRO QUE SE QUIERE ORDENAR > decreciente
- If (X[J].nombre > X[I].nombre) Then //<---aqui elijo el campo a ordenar
- Begin
- Swap(X[J], X[I]);
- Done := false
- End;
- End;
- Until Done;
- End;
- mostrarVector(X,N);
- End;
- (*-------------------------- S H E L L S O R T(METODO SHELL) CRECIENTE ---------------------*)
- Procedure ShellSortCreciente(Var X : TVEmpleados; N: Integer);
- Var
- Done: Boolean;
- Jump,I,J: Integer;
- Begin
- Jump := N;
- While (Jump > 1) Do
- Begin
- Jump := Jump Div 2;
- Repeat
- Done := true;
- For J := 1 To (N - Jump) Do
- Begin
- I := J + Jump;
- //AGREGAR LOS CAMPOS DEL REGISTRO QUE SE QUIERE ORDENAR > decreciente
- If (X[J].nombre > X[I].nombre) Then //<---aqui elijo el campo a ordenar
- Begin
- Swap(X[J], X[I]);
- Done := false
- End;
- End;
- Until Done;
- End
- End;
- Procedure StrSelectSortDecreciente(Var X : TVEmpleados; N : Integer);
- Var
- I,J,K : Integer;
- Y:TEmpleado; //tiene que ser un registro
- Begin
- //ordenacion por seleccion
- For I := 1 To N - 1 Do
- Begin
- K := I;
- Y:= x[I];//guardo un registro en Y
- For J := (I + 1) To N Do
- //aqui es donde tengo que elegir el campo a ordenar > DECRECIENTE
- If (X[J].nombre > Y.nombre) Then//esta la parte importante elijo el campo por el que quiero ordenar
- Begin
- K := J;
- Y := X[J];
- End;
- X[K] := X[I];
- X[I] := Y;
- End;
- mostrarVector(X,N);
- end;
- Procedure StrSelectSortCreciente(Var X : TVEmpleados; N : Integer);
- Var
- I,J,K : Integer;
- Y:TEmpleado; //tiene que ser un registro
- Begin
- //ordenacion por seleccion
- For I := 1 To N - 1 Do
- Begin
- K := I;
- Y:= x[I];//guardo un registro en Y
- For J := (I + 1) To N Do
- //aqui es donde tengo que elegir el campo a ordenar < CRECIENTE
- If (X[J].nombre < Y.nombre) Then//esta la parte importante elijo el campo por el que quiero ordenar
- Begin
- K := J;
- Y := X[J];
- End;
- X[K] := X[I];
- X[I] := Y;
- End;
- mostrarVector(X,N);
- end;
- **********************************************************
- procedure insertarPersona(var v: t_vectorPer;var n:Integer);
- var
- posLegB,legajoB,pos,i:integer;
- begin
- WriteLn('ingrese el legajo a insertar: ');
- ReadLn(legajoB);//legajo a buscar
- posLegB:= BuscarPosPersona(v,n,legajoB);
- //si posLegB = a un numero --> ya existe el legajo osea repetido
- //si posLegB = 0 -.>no existe el legajo portanto puedo insertar.
- while(posLegB<>0) do
- begin
- WriteLn('***el legajo ya exite **');
- WriteLn('ingrese el legajo a insertar: ');
- ReadLn(legajoB);
- posLegB:= BuscarPosPersona(v,n,legajoB);
- end;
- WriteLn('ingrese una posicion a insertar');
- ReadLn(pos);
- for i:=n downto pos do
- begin
- v[i+1]:=v[i];
- end;
- //empiezo a insertar el nombre, sector
- with v[pos] do
- begin
- legajo:=legajoB;
- WriteLn('Ingrese un nombre a insertar ');
- ReadLn(nombre);
- WriteLn('Ingrese el sector a insertar');
- ReadLn(sector);
- end;
- WriteLn('***insercion exitosa***');
- n:=n+1; //aumento n xq se inserto un registro mas
- end;
- **************************************************
- Procedure StrSelectSort(Var X : t_vectorPer; N : Integer);
- Var
- I,J,K : Integer;
- Y:RPersona;
- Begin
- //ordenacion por seleccion
- For I := 1 To N - 1 Do
- Begin
- K := I;
- Y:= x[I];//guardo un registro en Y
- For J := (I + 1) To N Do
- //aqui es donde tengo que elegir el campo a ordenar
- // < CRECIENTE
- // > DECRECIENTE
- If (X[J].nombre < Y.nombre) Then//esta la parte importante
- Begin
- K := J;
- Y := X[J];
- End;
- X[K] := X[I];
- X[I] := Y;
- End;
- MostrarVectorDePersonas(X,N);
- end;
- ***************************************************************
- procedure modificarPersona(var v:t_vectorPer;n:integer);
- var
- legajoB,posLegB:integer;
- begin
- WriteLn('ingrese el legajo a modificar: ');
- ReadLn(legajoB);
- posLegB:= BuscarPosPersona(v,n,legajoB);
- while(posLegB=0) do
- begin
- WriteLn('***el legajo no exite **');
- WriteLn('ingrese el legajo a modificar: ');
- ReadLn(legajoB);
- posLegB:= BuscarPosPersona(v,n,legajoB);
- end;
- with v[poslegB] do
- begin
- legajo:=legajoB;
- WriteLn('Ingrese un nombre');
- ReadLn(nombre);
- WriteLn('Ingrese el sector');
- ReadLn(sector);
- end;
- WriteLn('***modificacion exitosa***');
- end;
- ***********************************************************************
- ********************************************************
- Procedure StrInsert(Var X : tvector; N : Integer);
- Var
- K,J: Integer;
- Found: Boolean;
- Begin
- For J := 2 To N Do
- Begin
- K := J - 1;
- Found := false;
- While (K >= 1) And (Not Found) Do
- If (X[J].apellido < X[K].apellido) Then
- Begin
- X[K + 1] := X[K];
- K := K - 1
- End
- else
- Found := true;
- X[K + 1] := X[J];
- End
- End;
- **************************************************************
- Procedure ShellSort(Var V : tvector; N : Integer);
- Var
- Done: Boolean;
- Jump,I,J : Integer;
- Begin
- Jump := N;
- While (Jump > 1) Do
- Begin
- Jump := Jump Div 2;
- Repeat
- Done := true;
- For J := 1 To (N - Jump) Do
- Begin
- I := J + Jump;
- If (V[J].apellido > V[I].apellido) Then
- Begin
- Swap(V[J], V[I]);
- Done := false
- End;
- End;
- Until Done;
- End
- End;
- ********************************************************
- function BusquedaSecuencial(v: t_vectorPer;n:Integer; legajoBus:integer):boolean;
- var
- bandB:boolean;
- i:Integer;
- begin
- bandB:=false;
- for i:=1 to n do
- begin
- if(v[i].legajo=legajoBus) then
- begin
- bandB:= true;
- end
- end;
- BusquedaSecuencial:=bandB;
- end;
- ************************************************************************
- function BusquedaBinario(V:t_vectorPer; N:Integer;elem:integer):integer;
- var
- posInicial, posFinal, medio:integer;
- begin
- posInicial := 1;
- posFinal := N;
- BusquedaBinario := 0;
- repeat
- medio:=(posInicial+posFinal)div 2;
- if elem=V[medio].Legajo then
- BusquedaBinario := medio
- else
- //aqui va porque campo quiero buscar
- if elem<V[medio].Legajo then
- posFinal:=medio-1
- else
- posInicial:=medio+1;
- until (posInicial>posFinal) or (BusquedaBinario<>0);
- end;
- ************************************************************************************
- program Ordenacion;
- {$mode objfpc}{$H+}
- uses crt;
- type
- TReg = Record
- cod: char;
- precio: real;
- end;
- TArrReg = array[1..10]of TReg;
- var
- L : TArrReg;
- R : TReg;
- N : integer;
- procedure cargarVector(var L: TArrReg; var N: Integer);
- var
- i: integer;
- begin
- write('Ingrese la cantidad de datos: ');
- readln(N);
- for i := 1 to N do
- begin
- write('Ingrese codigo: ');
- readln(L[i].cod );
- write('Ingrese precio: ');
- readln(L[i].precio );
- end;
- end;
- procedure mostrarVector(L: TArrReg; N: Integer);
- var
- i: integer;
- begin
- for i := 1 to N do
- begin
- writeln('Codigo: ', L[i].cod);
- writeln('Precio: ', L[i].precio:7:2);
- end;
- end;
- Procedure Swap(Var X, Y : TReg);
- Var
- Temp: TReg;
- Begin
- Temp:= X;
- X:= Y;
- Y:= Temp
- End;
- Procedure BubbleSort(Var X : TArrReg; N : Integer);
- Var
- I, J : Integer;
- Begin
- For I := 2 To N Do
- Begin
- For J := N Downto I Do
- If (X[J].cod > X[J - 1].cod) Then
- Swap(X[J - 1], X[J]);
- End
- End;
- begin
- writeln('Bienvenido a mi programa...');
- cargarVector(L, N);
- mostrarVector(L,N);
- BubbleSort(L,N);
- readkey;
- writeln('Los datos ordenados son');
- mostrarVector(L,N);
- readkey;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement