1.Stack (tumpukan)
PROGRAM STACK_TUMPUKAN;
Uses wincrt;
Type
Nama = array [1..5] of String;
Var
Stack : Nama;
Top : Byte;
I,J,K : Integer;
Ch : Char;
Procedure Cuwil;
Begin
Top := 0;
Repeat
ClrScr;
Top:=Top+1;
If Top <=5 Then
Begin
For I:=Top downto 1 Do
Begin
WriteLn(I,'. ',Stack[I]);
End;
GotoXY(1,1);
Write('Nama ke-',Top,' : ');
ReadLn(Stack[Top]);
For I:=Top downto 1 Do
Begin
WriteLn(I,'. ',Stack[I]);
End; J:=Top;
Write('Tambahkan nama ? (Y/T) : '); ReadLn(Ch);
End
Else
Begin
WriteLn('STOP!!'); ReadLn;
Ch:='T';
End;
Until UpCase(Ch)='T';
End;
Procedure Struk;
Begin
Repeat
ClrScr;
For I:=J downto 1 Do
Begin
GotoXY(10,15-I);
WriteLn(I,'. ',Stack[I]);
End;
K:=0;
For I:=Top Downto J+1 Do
Begin
K:=K+1;
GotoXY(50,(10+I));
WriteLn(K,'. ',Stack[I]);
End;
GotoXY(1,1);
Write('Ambil Nama? (Y/T) : ');ReadLn(Ch);
If UpCase(Ch) = 'Y' Then
J:=J-1; If J<0 then
Begin
ClrScr;
WriteLn('Nama Habis!!');
ReadLn;
Ch:='T';
End;
Until Upcase(Ch)='T';
End;
Begin
Cuwil;
Struk;
End.
2. Pascal Queue (ANTRIAN)
Uses wincrt;
Type
Nama = array [1..5] of String;
Var
Stack : Nama;
Top : Byte;
I,J,K : Integer;
Ch : Char;
Procedure Cuwil;
Begin
Top := 0;
Repeat
ClrScr;
Top:=Top+1;
If Top <=5 Then
Begin
For I:=Top downto 1 Do
Begin
WriteLn(I,'. ',Stack[I]);
End;
GotoXY(1,1);
Write('Nama ke-',Top,' : '); ReadLn(Stack[Top]);
For I:=Top downto 1 Do
Begin
WriteLn(I,'. ',Stack[I]);
End;
J:=Top;
Write('Tambahkan nama ? (Y/T) : '); ReadLn(Ch);
End
Else
Begin
WriteLn('STOP!!'); ReadLn; Ch:='T';
End;
Until UpCase(Ch)='T';
End;
Procedure Struk;
Begin
K:=1;
Repeat
ClrScr;
For I:=K to J Do
Begin
GotoXY(10,15-I); WriteLn(I,'. ',Stack[I]);
End;
GotoXY(1,1); Write('Ambil Nama? (Y/T) : ');ReadLn(Ch);
If UpCase(Ch) = 'Y' Then K:=K+1; If K>J then
Begin
ClrScr;
WriteLn('Nama Habis!!');
ReadLn;
Ch:='T';
End;
Until Upcase(Ch)='T';
End;
Begin
Cuwil;
Struk;
End.