{ TIPOS DE DADOS } Const PILHA_TAM = 10; Type TPilha_Dado = Integer; TPilha = Record Dado: array [1..PILHA_TAM] of TPilha_Dado; Base,Topo: Integer; End; { ROTINAS } Procedure Pilha_Inicializa (Var P: TPilha); Begin P.Base := 1; P.Topo := 0; End; { PUSH } Function Pilha_Insere (Var P: TPilha; Dado: TPilha_Dado): Boolean; Begin IF P.Topo = PILHA_TAM { Testa overflow – Pilha cheia } THEN Pilha_Insere := False ELSE Begin P.Topo := P.Topo + 1; P.Dado [P.Topo] := Dado; Pilha_Insere := True; End; End; { POP } Function Pilha_Retira (Var P: TPilha; Var Dado: TPilha_Dado): Boolean; Begin IF P.Topo < P.Base { Testa Underflow – Pilha Vazia } THEN Pilha_Retira := False ELSE Begin Dado := P.Dado [P.Topo]; P.Topo := P.Topo - 1; Pilha_Retira := True; End; End; Procedure Pilha_Exibe (P: TPilha); Var aux: Integer; Begin Writeln('Base:'); FOR aux:=P.Base TO P.Topo DO Writeln (P.Dado[aux]); Writeln('Topo:'); Write ('Tecle ENTER para continuar...'); Readln; End; Procedure Pilha_Esvazia (Var P: TPilha); Var Dado: TPilha_Dado; Begin WHILE Pilha_Retira (P, Dado) DO ; End; (* Rotinas complementares... Function Pilha_Vazia (P: TPilha): Boolean; { Testa para ver se a pilha está vazia } Function Pilha_Quantidade (P: TPilha): Integer; { Indica quantos dados tem na pilha } Procedure Pilha_Inverte (Var P: TPilha); { Inverte a ordem dos dados da pilha } Procedure Pilha_Grava (Var ArqTxt: Text; P: TPilha); { Salva em disco os dados } Function Pilha_Le (Var ArqTxt: Text; Var P:TPilha); { Le do disco os dados } *)