STACK ADT By Pantharee S.
Stack Model A list with the restriction that insertions deletions can be performed in only one position (LIFO) Push – insert into stack. Pop – deletes the most recently inserted element. Push and Pop on an empty stack is ERROR in stack ADT Push on the running out of space is implementation error but not an ADT error
Stack
Operations
Postfix Expressions When a number is seen It is pushed onto the stack When an operator is seen POP two numbers(symbols) from the stack and plly the operator on them. Push the result onto the stack.
Example * *
จงบอกผลการทำงานจากบนลงล่าง Push(A)A. A Push(B)B. B Push(C)C. C PopD. D Push(D)E. Void Pop
ข้อใดทำการ push(e) A. elementData[--size] = e; B. elementData[size--] = e; C. elementData[++size] = e; D. elementData[size++] = e;
ข้อใดทำการ pop() A. elementData[--size] = null; B. elementData[size--] = null; C. elementData[++size] = null; D. elementData[size++] = null;
จงแสดงวิธีหาผลลัพธ์ของสมการ Postfix ดังต่อไปนี้ โดยใช้ Stack * * * +