assignment6a

O p c o d e o p a s s o c i a t i v i t y o p p r e c

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t o p && s t a c k t o p −>type == OPERATOR && ( o p p r e c e d e n c e s [ s t a c k t o p −>v a l u e . o p c o d e ] > o p p r e c e d e n c e s [ ptoken −>v a l u e . o p c o d e ] | | ( o p p r e c e d e n c e s [ s t a c k t o p −>v a l u e . o p c o d e ] == o p p r e c e d e n c e s [ ptoken −>v a l u e . o p c o d e ] && o p a s s o c i a t i v i t y [ o p p r e c e d e n c e s [ ptoken −>v a l u e . o p c o d e ] ] == LEFT ) ) ) e nqueue(& q u e u e p o s t f i x , p op(& s t a c k t o p ) ) ; push(& s t a c k t o p , p token ) ; break ; case LPARENS: / ∗ pushed t o o p e r a t o r s t a c k ∗ / p ush(& s t a c k t o p , p token ) ; break ; case RPARENS: / ∗ p op o p e r a t o r s o f f s t a c k u n t i l l e f t p a r e n t h e s e s r e a c h e d ∗ / f r e e ( ptoken ) ; / ∗ p a r e n t h e s e s n ot i n c l u d e d i n p o s t f i x q ueue ∗ / w hile ( ( ptoken = p op(& s t a c k t o p ) ) ) { i f ( ptoken −>type == LPARENS) { f r e e ( ptoken ) ; break ; } enqueue(& q u e u e p o s t f i x , p token ) ; } } } while ( s t a c k t o p ) / ∗ p op r e m a i n i n g o p e r a t o r s o f f s t a c k ∗ / enqueue(& q u e u e p o s t f i x , p op(& s t a c k t o p ) ) ; return q u e u e p o s t f i x ; } Problem 6.2 A useful data structure for storing lots of strings is the “trie.” This tree structure has the special property that a node’s key is a prefix of the keys of its children. For instance, if we associate a node with the string “a,” that node may have a child node with the key “an,” which in turn may have a child node “any.” When many strings share a common prefix, this structure is a very inexpensive 4 way to store them. Another consequence of this storage method is that the trie supports very fast searching – the complexity of finding a string with m characters is O(m). (root) � pointer array of childre � � � � � � � "a&quot...
View Full Document

Ask a homework question - tutors are online