Algoritma dan Struktur Data Stack
Tumpukan piring
ADT Stack Stack merupakan list dengan operasi insert dan delete sedemikian hingga node yang terakhir diinsertkan merupakan node yang pertama kali didelete Stack biasanya digambarkan sebagai tumpukan barang di mana operasi insert dan delete dilakukan di bagian puncak tumpukan Operasi stack : isFull, isEmpty, makeEmpty, push, pop, top. pop (delete) push (insert) top
Implementasi Stack Bisa menggunakan Array atau Linked List
Operasi Stack Beberapa operasi stack Push Stack Pop Stack Stack Top Empty Stack Full Stack Stack Count Destroy Stack
Create Stack stack.count = 0 stack.top = null return
Push if (stack full) success = false else allocate (newPtr) newPtr->data = data newPtr->next = stack.top stack.top = newPtr stack.count = stack.count + 1 success = true end if return success
Pop if (stack empty) success = false else dltPtr = stack.top dataOut = stack.top->data stack.top = stack.top->next stack.count = stack.count – 1 recycle (dltPtr) success = true end if return success
Stack Top if (stack empty) success = false else dataOut = stack.top->data success = true end if return success
Empty Stack if (stack not empty) result = false else result = true end if return result
Full Stack if (memory available) result = false else result = true end if return result
Stack Count return (stack.count)
Destroy Stack loop (stack.top not null) temp = stack.top stack.top = stack.top->next recycle (temp) end loop stack.count = 0 return