Dynamic Array Stack (Pop method)



Dynamic Array (Pop, Push, IntToHex methods)
Smart pascal source code
type TRec = record V: Integer; N: string; procedure ShowWriteln; begin Writeln(IntToStr(V) + ', ' + N); end; end; { main.pas unit} var a: array of Integer; r: array of TRec; i: Integer; buf: TRec; procedure PopAFew(n: Integer; a: array of Integer; r: array of TRec); begin while n > 0 do begin Writeln(a.Pop); Writeln(': '); r.Pop.ShowWriteln; Dec(n); end; end; procedure printData; begin Writeln('Remain: ' + IntToStr(Length(a)) + ', ' + IntToStr(Length(r))); end; begin for i := 1 to 10 do begin buf.V := i * 2; buf.N := UpperCase(IntToHex(buf.V, 2)); r.Push(buf); a.Push(i); end; PopAFew(5, a, r); { outputs 10 : 20, 14 9 : 18, 12 8 : 16, 10 7 : 0E 6 : 0C } printData; // Remain: 5, 5 i := a.Pop; buf := r.Pop; printData; // Remain: 4, 4 PopAFew(4, a, r); { outputs 4 : 8, 08 3 : 6, 06 2 : 4, 04 1 : 2, 02 } printData; // Remain: 0, 0