stack adt
Download
Skip this Video
Download Presentation
Stack ADT

Loading in 2 Seconds...

play fullscreen
1 / 83

Stack ADT - PowerPoint PPT Presentation


  • 139 Views
  • Uploaded on

Stack ADT. Operations Push, Pop, Top, isEmpty Application: Expression Evaluation Arithmetic Expression Infix-to-Postfix Postfix to Quadruples Boolean Expressions (Assignment #1) Infix-to-Postfix Postfix to Quadruples. Implementing a Stack. Using Vector /Array

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' - cera


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
  • Operations
  • Push, Pop, Top, isEmpty
  • Application: Expression Evaluation
  • Arithmetic Expression
    • Infix-to-Postfix
    • Postfix to Quadruples
  • Boolean Expressions (Assignment #1)
    • Infix-to-Postfix
    • Postfix to Quadruples
implementing a stack
Implementing a Stack
  • Using Vector /Array
    • requires estimate of maximum list length
    • may grow dynamically
    • Ø = empty slots
    • Can contain varied data/objects (not necessarily homogeneous)

212 rules!

Ø

Ø

Ø

30−0

Golf #1

top

slide3
Implementing a Stack
  • Using Linked List
    • flexible, adjusts to problem size
    • implementing a linked list
      • nodes and references/links/pointers

top

Ø

212 rules!

Golf #1

30−0

slide4
Implementing a Stack

0

1

2

3

4

5

6

7

8

2

-1

7

-1

1

4

3

6

0

Ø

  • Using Linked List
    • implementing a linked list
      • cursor implementation

212 rules!

Ø

Ø

30−0

top = 5

Golf #1

freelist = 8

Ø

Ø

Ø

implementing a stack1
Implementing a Stack

Vector/Array Linked List

  • push O(1)* O(1)
  • pop O(1) O(1)
  • top/peek O(1) O(1)
  • isEmpty O(1) O(1)

*assuming no need for Vector/Array expansion

infix to postfix
Infix to Postfix

infix expression: z = a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression:

@

slide7
Infix to Postfix

infix expression: z= a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z

@

slide8
Infix to Postfix

infix expression: z= a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z

=

@

slide9
Infix to Postfix

infix expression: z=a * ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a

=

@

slide10
Infix to Postfix

infix expression: z=a* ( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a

*

=

@

slide11
Infix to Postfix

infix expression: z=a*( x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a

(

*

=

@

slide12
Infix to Postfix

infix expression: z=a*(x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x

(

*

=

@

slide13
Infix to Postfix

infix expression: z=a*(x + y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x

+

(

*

=

@

slide14
Infix to Postfix

infix expression: z=a*(x +y ) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y

+

(

*

=

@

slide15
Infix to Postfix

infix expression: z=a*(x +y) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y +

(

*

=

@

slide16
Infix to Postfix

infix expression: z=a*(x +y) + z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y +

*

=

@

slide17
Infix to Postfix

infix expression: z=a*(x +y)+ z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y + *

=

@

slide18
Infix to Postfix

infix expression: z=a*(x +y)+ z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y + *

+

=

@

slide19
Infix to Postfix

infix expression: z=a*(x +y)+z * c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y + *z

+

=

@

slide20
Infix to Postfix

infix expression: z=a*(x +y)+z* c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y + *z

*

+

=

@

slide21
Infix to Postfix

infix expression: z=a*(x +y)+z*c ^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y + *z c

*

+

=

@

slide22
Infix to Postfix

infix expression: z=a*(x +y)+z*c^ ( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y + *z c

^

*

+

=

@

slide23
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2 − ( − d + w ) ) / x ;

postfix expression: z a x y + *zc

(

^

*

+

=

@

slide24
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2− ( − d + w ) ) / x ;

postfix expression: z a x y + *z c 2

(

^

*

+

=

@

slide25
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2− ( − d + w ) ) / x ;

postfix expression: z a x y + *z c 2

(

^

*

+

=

@

slide26
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(− d + w ) ) / x ;

postfix expression: z a x y + *z c 2

(

(

^

*

+

=

@

slide27
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(− d + w ) ) / x ;

postfix expression: z a x y + *z c 2

~

(

(

^

*

+

=

@

slide28
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d + w ) ) / x ;

postfix expression: z a x y + *z c 2 d

~

(

(

^

*

+

=

@

slide29
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+ w ) ) / x ;

postfix expression: z a x y + *z c 2 d

~

(

(

^

*

+

=

@

slide30
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+ w ) ) / x ;

postfix expression: z a x y + *z c 2 d ~

(

(

^

*

+

=

@

slide31
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+ w ) ) / x ;

postfix expression: z a x y + *z c 2 d ~

+

(

(

^

*

+

=

@

slide32
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w ) ) / x ;

postfix expression: z a x y + *z c 2 d ~ w

+

(

(

^

*

+

=

@

slide33
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w) ) / x ;

postfix expression: z a x y + *z c 2 d ~w

+

(

(

^

*

+

=

@

slide34
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w) ) / x ;

postfix expression: z a x y + *z c 2 d ~w +

(

(

^

*

+

=

@

slide35
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w) ) / x ;

postfix expression: z a x y + *z c 2 d ~w +

(

(

^

*

+

=

@

slide36
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w) ) / x ;

postfix expression: z a x y + *z c 2 d ~w +

(

^

*

+

=

@

slide37
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w)) / x ;

postfix expression: z a x y + *z c 2 d ~w +

(

^

*

+

=

@

slide38
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w)) / x ;

postfix expression: z a x y + *z c 2 d ~w + −

(

^

*

+

=

@

slide39
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w)) / x ;

postfix expression: z a x y + *z c 2 d ~w + −

^

*

+

=

@

slide40
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/ x ;

postfix expression: z a x y + *z c 2 d ~w + −

^

*

+

=

@

slide41
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/ x ;

postfix expression: z a x y + *z c 2 d ~w + − ^

*

+

=

@

slide42
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/ x ;

postfix expression: z a x y + *z c 2 d ~w + − ^ *

+

=

@

slide43
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/ x ;

postfix expression: z a x y + *z c 2 d ~w + − ^ *

/

+

=

@

slide44
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/x ;

postfix expression: z a x y + *z c 2 d ~w + − ^ * x

/

+

=

@

slide45
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/x;

postfix expression: z a x y + *z c 2 d ~w + − ^ * x

/

+

=

@

slide46
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/x;

postfix expression: z a x y + *z c 2 d ~w + − ^ * x /

+

=

@

slide47
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/x;

postfix expression: z a x y + *z c 2 d ~w + − ^ * x / +

=

@

slide48
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/x;

postfix expression: z a x y + *z c 2 d ~w + − ^ * x / + =

@

slide49
Infix to Postfix

infix expression: z=a*(x +y)+z*c^( 2−(−d+w))/x;

postfix expression: z a x y + *z c 2 d ~w + − ^ * x / + =

slide50
Postfix to Quadruples

postfix expression: z a x y + * z c 2 d ~w + − ^ * x / + =

z

slide51
Postfix to Quadruples

postfix expression: za x y + * z c 2 d ~w + − ^ * x / + =

a

z

slide52
Postfix to Quadruples

postfix expression: zax y + * z c 2 d ~w + − ^ * x / + =

x

a

z

slide53
Postfix to Quadruples

postfix expression: zaxy + * z c 2 d ~w + − ^ * x / + =

y

x

a

z

slide54
Postfix to Quadruples

postfix expression: zaxy+* z c 2 d ~w + − ^ * x / + =

y

x

a

z

slide55
Postfix to Quadruples

postfix expression: zaxy+* z c 2 d ~w + − ^ * x / + =

t0

a

z

+ x y t0

slide56
Postfix to Quadruples

postfix expression: zaxy+*z c 2 d ~w + − ^ * x / + =

+ x y t0

t0

a

z

slide57
Postfix to Quadruples

postfix expression: zaxy+*z c 2 d ~w + − ^ * x / + =

+ x y t0

* a t0 t1

t1

z

slide58
Postfix to Quadruples

postfix expression: zaxy+*zc 2 d ~w + − ^ * x / + =

+ x y t0

* a t0 t1

z

t1

z

slide59
Postfix to Quadruples

postfix expression: zaxy+*zc2 d ~w + − ^ * x / + =

+ x y t0

* a t0 t1

c

z

t1

z

slide60
Postfix to Quadruples

postfix expression: zaxy+*zc2d ~w + − ^ * x / + =

+ x y t0

* a t0 t1

2

c

z

t1

z

slide61
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w + − ^ * x / + =

+ x y t0

* a t0 t1

d

2

c

z

t1

z

slide62
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w + − ^ * x / + =

+ x y t0

* a t0 t1

d

2

c

z

t1

z

slide63
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w + − ^ * x / + =

+ x y t0

* a t0 t1

~ d t2

t2

2

c

z

t1

z

slide64
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w + − ^ * x / + =

+ x y t0

* a t0 t1

~ d t2

w

t2

2

c

z

t1

z

slide65
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+ − ^ * x / + =

+ x y t0

* a t0 t1

~ d t2

w

t2

2

c

z

t1

z

slide66
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+ − ^ * x / + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

t3

2

c

z

t1

z

slide67
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+− ^ * x / + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

t3

2

c

z

t1

z

slide68
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+− ^ * x / + =

+ x y t0

* a t0 t1

~ d t2

+ t2 2 t3

- w t3 t4

t4

c

z

t1

z

slide69
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^* x / + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

t4

c

z

t1

z

slide70
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^* x / + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

t5

z

t1

z

slide71
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x / + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

t5

z

t1

z

slide72
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x / + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

t6

t1

z

slide73
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x / + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

x

t6

t1

z

slide74
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/ + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

x

t6

t1

z

slide75
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/ + =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

t7

t1

z

slide76
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/+ =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

t7

t1

z

slide77
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/+ =

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

+ t1 t7 t8

t8

z

slide78
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/+=

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

+ t1 t7 t8

t8

z

slide79
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/+=

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

+ t1 t7 t8

= t8 z

slide80
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/+=

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

+ t1 t7 t8

t8

z

slide81
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/+=

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

+ t1 t7 t8

= t8 z

slide82
Postfix to Quadruples

postfix expression: zaxy+*zc2d~w+−^*x/+=

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

+ t1 t7 t8

= t8 z

slide83
Postfix to Quadruples

infix expression: z=a * (x +y)+z * c^( 2 −(−d+w))/x;

--- t0 --- -t2-

----- t1 ------ ---- t3 ----

-------- t4 --------

----------- t5 -----------

-------------- t6 -------------

----------------- t7 --------------

---------------------- t8 ---------------------------

+ x y t0

* a t0 t1

~ d t2

+ t2 w t3

- w t3 t4

^ c t4 t5

* Z t5 t6

/ t6 x t7

+ t1 t7 t8

= t8 z

postfix expression: zaxy+*zc2d~w+−^*x/+=

ad