A priority queue of strings is implemented using a heap. The heap contains the f
ID: 3654841 • Letter: A
Question
A priority queue of strings is implemented using a heap. The heap contains the following elements: numElements [10] .elements [0] "introspective" [1] "intelligent" [2] "intellectual" [3] "intimate" [4] "intensive" [5] "interesting" [6] "internal" [7] "into" [8] "in" [9] "intro (a) What feature of these strings is used to determine their priority in the priority queue? (b) Show how this priority queue is affected by adding the string "interviewing."Explanation / Answer
a). By depaneds on priority what we are give to thatstring for natural priority ---- public PriorityQueue(int initialCapacity), If we consider oncapacity, than capacity() function returns thenumber of elements that the string can hold. #include size_type capacity()const and If we consider on the length,length() function returns the number of elementsin the current string. #include size_type length() const consider on size, max_size() function returns the maximumnumber of elements that can hold. #include size_type length() const ------------------------------------------------------------------------------------------------ b). The PriorityQueue class implements the Queue interface .ThePriorityQueue class is comes from “System.Collections”namespace. It is generic. queue priqu = newPriorityQueue(); for Ex: for (int i = 10; i >= 1; i--) { string str = "" + i; stk.push(str); qu.add(str); priqu.add(str); } while (! qu.isEmpty()) { string str = stk.pop(); str = qu.remove(); str = priqu.remove(); } And Comparison is done through the “IComparer”interface. Objects in the PriorityQueue need not have all the sametype but they have to be comparable with each other. The PriorityQueue have 3 main operations Push(), Pop(), andUpdate()Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.