please see my code :
there are something wrong?how i can check if stack is empty??
NB : isi = content of stack
atas = top of stack
tumpukan is stack

function POP (var T : Tumpukan) : integer;
 begin
        POP := T.Isi[T.Atas];
        T.Atas := dec[T.Atas];
 end;

anyhelp will be appreciated..
thanks guys

Recommended Answers

All 4 Replies

please see my code :
there are something wrong?how i can check if stack is empty??
NB : isi = content of stack
atas = top of stack
tumpukan is stack

function POP (var T : Tumpukan) : integer;
 begin
        POP := T.Isi[T.Atas];
        T.Atas := dec[T.Atas];
 end;

i was modified your code and add a some code :
i use your initial code...

function POP (var T : Tumpukan) : integer;

 {*this function to check stack is empty or not*}
 function Empty(var T : Tumpukan): boolean;

 begin
   Empty := (T.Atas = 0)
 end;      

 begin
   if Empty(T) then
      POP := 0
   else
      begin
        POP := T.Isi[T.Atas];
        T.Atas := dec[T.Atas];
      end;
 end;

Ok. Hope this helps....

commented: helping much, thanks for empty function. you are really good guy with smart code :) +1
commented: hei, i get this one too +1

thanks jx_man...
its very cool....
:)

so i just to set the top of stack = 0 to build the empty function. thanks man. looks easy now.
Ok. see you again.:D

yes, you right.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.