Stack has two variables.
- Top -> Used to store address of the top element of a stack.
- Max -> Used to store the maximum number that can be stacked.
If TOP = Null, stack is empty, if TOP = max -1 , then stack is full.
Insertion & Deletion will be done at TOP.
Stack Operations.
- Push(x) = add an item x to the top of stack
- Pop( ) = remove item from top of stack
- Top( ) = reveal the top item from stack (Top = Peek)
Queue
Front = Rear = -1
Ketika ada yang masuk, misal push (5,3,7,12), rear ditambah 1, jadi rear = 0. cek rear + 1 apakah >= max, jika tidak, lanjutkan terus
pop( ) front + 1 >= rear. jika tidak, lanjutkan terus
Prefix, Postfix
4+6*(5-2)/3 = +4/*6-523
Caranya: Prefix, liat paling duluan.
- Kurang dulu, prefix operator kiri. Terus operand kiri kanan tentukan.
– 5 2
2. Next yang tanda * dulu, di kiri. Angka 6 di kirinya (5-3)
*6-52
Seterusnya sampai selesai.
DFS ( Depth First Search), turun dulu ke paling dalam.
BFS (Breath First Search), mencarinya secara menyisir dari kiri- kanan ataupun kanan – kiri.