Stack c6
-
Upload
omar-al-sabek -
Category
Education
-
view
147 -
download
0
Transcript of Stack c6
Pascal Programming Language
Omar ElSabek & Fayez GhazzawiIT Engineering3th year – UNKNOWN Department
programming II
So the STACK is:
An Abstract Structure based on the principle (LIFO) “Last in First out”.
Thinking Of MAKDOOS right now :P :P :P :P .
It has two elements:
1. The Variable(s) with Data type(s) “the same with all the stacks elements”.
2. The References which refers to the next element in the Stack (it refers to the element underneath).This Reference has the value of (nil) in the Bottom of the Stack.
3. The Stack has the (Top) which refers to the top element in the Stack …. This is the reference we have keep :D.
Program test1;
Type
n_stack = ^stack;
stack = record
c : char;
next : n_stack;
end;
Now let’s meet with PUSH & POPas Procedures :P
Procedure Push (var top: n_stack ; ch: char)
Var
temp : n_stack;
Begin
new(temp);
temp^.c := ch;
temp^.next := top;
top := temp;
End;
Procedure Pop (var top: n_stack ;var ch: char)
Var
temp : n_stack;
Begin
ch := top^.c;
temp := top;
top := top^.next;
dispose (temp);
End;
Var
s : string[10]; ch:char;
top : n_stack;
Begin
top := nil;
read(s);
for i:=1 to 10 do
Push(top,S[i]);
while (top <> nil) do
begin
Pop(top,ch); write(ch);
end;
End.