Stack adt
Download
1 / 10

STACK ADT - PowerPoint PPT Presentation


  • 189 Views
  • Uploaded on

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

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' STACK ADT' - taji


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript
Stack adt

STACK ADT

By Pantharee S.


Stack model
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 ERRORin stack ADT

  • Push on the running out of space is implementation error but not an ADT error




Postfix expressions
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
Example

6 5 2 3 + 8 * + 3 + *


จงบอกผลการทำงานจากบนลงล่างจงบอกผลการทำงานจากบนลงล่าง

  • Push(A) A. A

  • Push(B) B. B

  • Push(C) C. C

  • Pop D. D

  • Push(D) E. Void

  • Pop

  • Pop


Push e
ข้อใดทำการ จงบอกผลการทำงานจากบนลงล่าง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
จงแสดงวิธีหาผลลัพธ์ของสมการ Postfix ดังต่อไปนี้ โดยใช้ Stack

3 4 5 * + 7 8 * 6 + 5 * +


ad