Stack adt
This presentation is the property of its rightful owner.
Sponsored Links
1 / 83

Stack ADT PowerPoint PPT Presentation


  • 91 Views
  • Uploaded on
  • Presentation posted in: General

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

Download Presentation

Stack ADT

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


Stack adt

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


Stack adt

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

  • pushO(1)*O(1)

  • popO(1)O(1)

  • top/peekO(1)O(1)

  • isEmptyO(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:

@


Stack adt

Infix to Postfix

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

postfix expression: z

@


Stack adt

Infix to Postfix

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

postfix expression: z

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a

*

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a

(

*

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x

(

*

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x

+

(

*

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y

+

(

*

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y +

(

*

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y +

*

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y + *

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y + *

+

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y + *z

+

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y + *z

*

+

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y + *z c

*

+

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y + *z c

^

*

+

=

@


Stack adt

Infix to Postfix

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

postfix expression: z a x y + *zc

(

^

*

+

=

@


Stack adt

Infix to Postfix

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

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

(

^

*

+

=

@


Stack adt

Infix to Postfix

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

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

(

^

*

+

=

@


Stack adt

Infix to Postfix

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

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

(

(

^

*

+

=

@


Stack adt

Infix to Postfix

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

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

~

(

(

^

*

+

=

@


Stack adt

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

~

(

(

^

*

+

=

@


Stack adt

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

~

(

(

^

*

+

=

@


Stack adt

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 ~

(

(

^

*

+

=

@


Stack adt

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 ~

+

(

(

^

*

+

=

@


Stack adt

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

+

(

(

^

*

+

=

@


Stack adt

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

+

(

(

^

*

+

=

@


Stack adt

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 +

(

(

^

*

+

=

@


Stack adt

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 +

(

(

^

*

+

=

@


Stack adt

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 +

(

^

*

+

=

@


Stack adt

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 +

(

^

*

+

=

@


Stack adt

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 + −

(

^

*

+

=

@


Stack adt

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 + −

^

*

+

=

@


Stack adt

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 + −

^

*

+

=

@


Stack adt

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 + − ^

*

+

=

@


Stack adt

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 + − ^ *

+

=

@


Stack adt

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 + − ^ *

/

+

=

@


Stack adt

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

/

+

=

@


Stack adt

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

/

+

=

@


Stack adt

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 /

+

=

@


Stack adt

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 / +

=

@


Stack adt

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 / + =

@


Stack adt

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 / + =


Stack adt

Postfix to Quadruples

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

z


Stack adt

Postfix to Quadruples

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

a

z


Stack adt

Postfix to Quadruples

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

x

a

z


Stack adt

Postfix to Quadruples

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

y

x

a

z


Stack adt

Postfix to Quadruples

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

y

x

a

z


Stack adt

Postfix to Quadruples

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

t0

a

z

+ x y t0


Stack adt

Postfix to Quadruples

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

+ x y t0

t0

a

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

t1

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

z

t1

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

c

z

t1

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

2

c

z

t1

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

d

2

c

z

t1

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

d

2

c

z

t1

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

~ d t2

t2

2

c

z

t1

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

~ d t2

w

t2

2

c

z

t1

z


Stack adt

Postfix to Quadruples

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

+ x y t0

* a t0 t1

~ d t2

w

t2

2

c

z

t1

z


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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


Stack adt

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/+=


  • Login