Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program OrganizaTbl;
- uses crt, SysUtils;
- type
- TOpcao = (CrescHoriz, CrescVert, DecHoriz, DecVert, Sair);
- var opcao: TOpcao;
- tabela: array of array of Integer;
- procedure DesenhaTbl(Linhas, Colunas: Integer);
- var c, l:Integer;
- begin
- WriteLn;
- writeln('Desenhando tabela . . . ');
- WriteLn;
- for l:=0 to Linhas - 1 do
- begin
- for c:=0 to Colunas - 1 do
- write(format('[%4d ]', [tabela[l, c]]));
- WriteLn;
- end;
- WriteLn;
- WriteLn('Pressione enter para continuar . . .');
- ReadLn;
- end;
- procedure PreencheArray(Linhas, Colunas: Integer);
- var c, l: Integer;
- begin
- SetLength(tabela, Linhas, Colunas);
- Randomize();
- for l:=0 to Linhas - 1 do
- for c:=0 to Colunas - 1 do
- begin
- tabela[l, c]:= random(1000);
- end;
- end;
- procedure OrdCrescHoriz;
- var aux, l, c: Integer;
- auxVetor: array of Integer;
- begin
- WriteLn('Reordenando o array . . .');
- aux:=-1;
- setlength(auxVetor, ((high(tabela)+1)*(high(tabela[0])+1)));
- for l:=0 to high(tabela) do
- for c:=0 to high(tabela[0]) do
- begin
- inc(aux);
- auxVetor[aux]:=tabela[l, c];
- end;
- for c:=0 to high(auxVetor) do
- for l:=1 to high(auxVetor) - c do
- begin
- if auxVetor[l] < auxVetor[l-1] then
- begin
- aux := auxVetor[l-1];
- auxVetor[l-1] := auxVetor[l];
- auxVetor[l] := aux;
- end;
- end;
- aux:=-1;
- for l:=0 to high(tabela) do
- for c:=0 to high(tabela[0]) do
- begin
- inc(aux);
- tabela[l, c]:=auxVetor[aux];
- end;
- l:=high(tabela);
- c:=high(tabela[l]);
- DesenhaTbl(l+1, c+1);
- end;
- procedure MenuDefineTbl;
- var lnhs, cls:Integer;
- begin
- while not (cls in [1..7]) do
- begin
- Write('De 1 à 7: quantas colunas terá a tabela? : ');
- ReadLn(cls);
- end;
- while not (lnhs in [1..20]) do
- begin
- Write('De 1 à 20: quantas linhas terá a tabela? : ');
- ReadLn(lnhs);
- end;
- PreencheArray(lnhs, cls);
- DesenhaTbl(lnhs, cls);
- end;
- function MenuOpcOrdem: TOpcao;
- var opc : Integer ;
- begin
- while not (opc in [1..5]) do
- begin
- WriteLn;
- WriteLn('Como você deseja organizar o array?');
- WriteLn;
- WriteLn('1: Para ordem crescente na horizontal.');
- WriteLn('2: Para ordem crescente na vertical.');
- WriteLn('3: Para ordem decrescente na horizontal.');
- WriteLn('4: Para ordem decrescente na vertical.');
- WriteLn('5: Para sair.');
- ReadLn(opc);
- case opc of
- 1: MenuOpcOrdem := CrescHoriz;
- 2: MenuOpcOrdem := CrescVert;
- 3: MenuOpcOrdem := DecHoriz;
- 4: MenuOpcOrdem := DecVert;
- 5: MenuOpcOrdem := Sair;
- end;
- end;
- end;
- begin
- opcao := CrescHoriz;
- while not (opcao = Sair) do
- begin
- clrscr();
- WriteLn('------ Organizar um array bidimensional ------');
- WriteLn;
- opcao := MenuOpcOrdem;
- if opcao <> Sair then
- MenuDefineTbl();
- case opcao of
- CrescHoriz: OrdCrescHoriz;
- CrescVert: {fazalgo};;
- DecHoriz: {fazalgo};;
- DecVert: {fazalgo};;
- Sair: WriteLn('Saindo, pressione enter . . .');
- end;
- end;
- ReadLn;
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement