You are on page 1of 2

DFC2023 – ALGORITHM AND DATA STRUCTURE

NAMA : THAYAABARAN S/O MANICKAM

METRIC .NO : 01DD19F1184

SECTION : DDTS3A

EXERCISE

Sketch the CORRECT memory diagram to each operation of Stack implement in linked list as below.

NO OPERATI CODE SYNTAX MEMORY DIAGRAM


ON
a) Typedef struct Num
Declare {
structure Int nilai;
of stack Struct Num*link
} stackA Num

b) Create stackA*Head;
stack Head = Null;

c) Check If(*t == Null)


stack cout<<”Stack empty”;
empty
d) Push i) Create new node
new item stackA*Ptr1;
to an Ptr1 = new Num;
empty Ptr1->nilai = 10;
Ptr1->link = Null;

ii) Set head point to


the new node
created
Head = Ptr1;
DFC2023 – ALGORITHM AND DATA STRUCTURE

e) Push i) Create new node


new item stackA*Ptr1;
to an Ptr1 = new Num;
existing Ptr1->nilai = 13;
stack Ptr1->link = Null;

ii) Set new node


created as first
node in the stack
Ptr1->link = Head;

iii) Set head point to


the new node
created
Head = Ptr1;

f) Pop item stackA* delPtr;


from delPtr = Head
stack Head = Head->link;
Delete delPtr;

You might also like