Sunteți pe pagina 1din 5

program stack_array_gurisa_com;

uses crt;

const

max = 5;

type

larik = array[1..max] of integer;

var

data:larik;

top, input_data, i, j, k, l, m:integer;

ulang, ulang_pop:char;

procedure create_stack(var top:integer);

begin

top := 0;

end;

function empty_stack(var top:integer):boolean;

begin

empty_stack := top = 0;
end;

function full_stack(var top:integer):boolean;

begin

full_stack := top = max;

end;

procedure push_data(var top, input_data:integer);

begin

if (not full_stack(top)) then

begin

data[top] := input_data;

top := top + 1;

end

else

begin

write('<STACK PENUH>');

end;

end;

procedure pop_data(var top, input_data:integer);

begin
if (not empty_stack(top)) then

begin

input_data := data[top];

top := top - 1;

end

else

begin

write('<STACK KOSONG>');

end;

end;

procedure show_stack(var top:integer; m:integer);

var

tmp:integer;

begin

tmp := top - 1;

if (not empty_stack(top)) then

begin

for l := tmp downto 0 do

begin

gotoxy(39,17+i+j+k+m);write(data[tmp]);

tmp := tmp - 1;

j := j + 1;
end;

end

else

begin

write('<STACK KOSONG>');

end;

end;

begin

repeat

create_stack(top);

i := 0;

j := 0;

k := 0;

l := 0;

m := 0;

textcolor(15);gotoxy(27,2);write('STACK DATA ARRAY GURISA.COM');

textcolor(14);gotoxy(27,3);write('~~~~~~~~~~~~~~~~~~~~~~~~~~~');

textcolor(10);gotoxy(32,5);write('DATA AWAL STACK');

textcolor(15);gotoxy(33,7);show_stack(top, 0);

textcolor(10);gotoxy(28,10);write('PUSH DATA KE DALAM STACK');

textcolor(15);

for i := 1 to max do

begin

gotoxy(32,12+i);write('Masukan Data : ');readln(input_data);


push_data(top, input_data);

end;

textcolor(10);gotoxy(30,14+i);write('DATA DI DALAM STACK');

textcolor(15);show_stack(top, 0);

textcolor(10);gotoxy(30,18+i+j);write('POP DATA DARI STACK');

repeat

textcolor(14);gotoxy(30,20+i+j+k+l);write('POP Data [Y/T] : ');readln(ulang_pop);

if ((ulang_pop = 'Y') or (ulang_pop = 'y')) and (not empty_stack(top)) then

begin

textcolor(15);gotoxy(25,22+i+j+k+l);pop_data(top, input_data);

k := k + 1;

end;

until (ulang_pop = 'T') or (ulang_pop = 't') or (empty_stack(top));

textcolor(10);gotoxy(31,23+i+j+k+l);write('DATA AKHIR STACK');

textcolor(15);gotoxy(32,25+i+j+k+l);show_stack(top, 9);

textcolor(14);gotoxy(27,28+i+j+k+l+m);write('Ulangi Program [Y/T] : ');readln(ulang);

clrscr();

until (ulang = 'T') or (ulang = 't');

end.

S-ar putea să vă placă și