diff --git a/.vscode/GTEMP.pas b/.vscode/GTEMP.pas index 42b0b07..ba0b90a 100644 --- a/.vscode/GTEMP.pas +++ b/.vscode/GTEMP.pas @@ -9,44 +9,6 @@ type THash = array[0..99] of TCPF; -procedure inserirCPF(var cpfs:THash; var cpf:string); - var - i, pos:integer; - novo, atual, ant:TCPF; - begin - if validarCPF(cpf) then - begin - pos:=(Ord(cpf[10])-48)*10 + (Ord(cpf[11])-48); //esse ngocio pega os digitos verificadores, gpt ajudou, transformar string em int é pesadelo - new(novo); - if novo = nil then - writeln('Memoria cheia'); - else - begin - novo^.cpf := cpf; - novo^.prox := nil; - atual:= hash[pos]; - ant:=nil - while (atual <> nil) and (atual^.cpf < cpf) do - begin - ant := atual; - atual := atual^.prox; - end; - if ant = nil then - begin - novo^.prox := hash[pos]; - hash[pos] := novo; - end - else - begin - novo^.prox := atual; - ant^.prox := novo; - end; - end; - end - else - writeln('CPF INVALIDO'); - end; - function validarCPF(var cpf:string):boolean; var i, soma, dig1, dig2:integer; @@ -69,13 +31,52 @@ function validarCPF(var cpf:string):boolean; if (dig2 = 10) or (dig2 = 11) then dig2 := 0; - ValidarCPF := (dig1=(Ord(cpf[10])-48)) and (dig2=(Ord(cpf[11])-48)); end; +procedure inserirCPF(var cpfs:THash; var cpf:string); + var + i, pos:integer; + novo, atual, ant:TCPF; + begin + if validarCPF(cpf) then + begin + pos:=(Ord(cpf[10])-48)*10 + (Ord(cpf[11])-48); //esse ngocio pega os digitos verificadores, gpt ajudou, transformar string em int é pesadelo + new(novo); + if novo = nil then + writeln('Memoria cheia') + else + begin + novo^.cpf := cpf; + novo^.prox := nil; + atual:= cpfs[pos]; + ant:=nil; + while (atual <> nil) and (atual^.cpf < cpf) do + begin + ant := atual; + atual := atual^.prox; + end; + if ant = nil then + begin + novo^.prox := cpfs[pos]; + cpfs[pos] := novo; + end + else + begin + novo^.prox := atual; + ant^.prox := novo; + end; + end; + end + else + writeln('CPF INVALIDO'); + end; + + + var hash: THash; @@ -83,6 +84,5 @@ var bool:boolean; begin readln(cpf); - bool:= validarCPF(cpf); - writeln(bool); + inserirCPF(hash,cpf); end. \ No newline at end of file diff --git a/cpfs b/cpfs index 21d28c9..7405bee 100755 Binary files a/cpfs and b/cpfs differ diff --git a/cpfs.o b/cpfs.o index e31a1c6..718c72c 100644 Binary files a/cpfs.o and b/cpfs.o differ diff --git a/cpfs.pas b/cpfs.pas index 42b0b07..ba0b90a 100644 --- a/cpfs.pas +++ b/cpfs.pas @@ -9,44 +9,6 @@ type THash = array[0..99] of TCPF; -procedure inserirCPF(var cpfs:THash; var cpf:string); - var - i, pos:integer; - novo, atual, ant:TCPF; - begin - if validarCPF(cpf) then - begin - pos:=(Ord(cpf[10])-48)*10 + (Ord(cpf[11])-48); //esse ngocio pega os digitos verificadores, gpt ajudou, transformar string em int é pesadelo - new(novo); - if novo = nil then - writeln('Memoria cheia'); - else - begin - novo^.cpf := cpf; - novo^.prox := nil; - atual:= hash[pos]; - ant:=nil - while (atual <> nil) and (atual^.cpf < cpf) do - begin - ant := atual; - atual := atual^.prox; - end; - if ant = nil then - begin - novo^.prox := hash[pos]; - hash[pos] := novo; - end - else - begin - novo^.prox := atual; - ant^.prox := novo; - end; - end; - end - else - writeln('CPF INVALIDO'); - end; - function validarCPF(var cpf:string):boolean; var i, soma, dig1, dig2:integer; @@ -69,13 +31,52 @@ function validarCPF(var cpf:string):boolean; if (dig2 = 10) or (dig2 = 11) then dig2 := 0; - ValidarCPF := (dig1=(Ord(cpf[10])-48)) and (dig2=(Ord(cpf[11])-48)); end; +procedure inserirCPF(var cpfs:THash; var cpf:string); + var + i, pos:integer; + novo, atual, ant:TCPF; + begin + if validarCPF(cpf) then + begin + pos:=(Ord(cpf[10])-48)*10 + (Ord(cpf[11])-48); //esse ngocio pega os digitos verificadores, gpt ajudou, transformar string em int é pesadelo + new(novo); + if novo = nil then + writeln('Memoria cheia') + else + begin + novo^.cpf := cpf; + novo^.prox := nil; + atual:= cpfs[pos]; + ant:=nil; + while (atual <> nil) and (atual^.cpf < cpf) do + begin + ant := atual; + atual := atual^.prox; + end; + if ant = nil then + begin + novo^.prox := cpfs[pos]; + cpfs[pos] := novo; + end + else + begin + novo^.prox := atual; + ant^.prox := novo; + end; + end; + end + else + writeln('CPF INVALIDO'); + end; + + + var hash: THash; @@ -83,6 +84,5 @@ var bool:boolean; begin readln(cpf); - bool:= validarCPF(cpf); - writeln(bool); + inserirCPF(hash,cpf); end. \ No newline at end of file