{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

T08_STLstr_t - Tutorial 8 COMP152 Spring 2010 STL and...

Info iconThis preview shows pages 1–8. Sign up to view the full content.

View Full Document Right Arrow Icon
STL and String Tutorial Tutorial 8 COMP152 Spring 2010
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Outline STL adapters Priority queue STL algorithms String streams Examples Case study: Text editing COMP152 2
Background image of page 2
STL's priority_queue Adapter A queue can be specified queue<T, C<T> > aQueue; C may be any container supporting push_back() and pop_front() The default container is vector Could also use priority_queue<T, deque<T> > aQueue; For the best performance, use class vector as the underlying container Enables insertions in sorted order and deletions from front Elements are inserted in priority order Highest-priority element will be the first to be removed Maintains sorted order via heapsort Comparison of elements is performed with comparator function object less<T> by default COMP152 3
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
STL's priority_queue Adapter Operations (call functions of the underlying container) push insert element at appropriate location to maintain sorted order (calls push_back, then reorders elements with heapsort) pop remove highest-priority element (moves top element of heap to back, then calls pop_back) top returns reference to top element (calls front) empty determine if the priority_queue is empty (calls empty) size get the number of elements (calls size) Again, each common operations is implemented as an inline function COMP152 4
Background image of page 4