课程: C# Practice: Generic Collections
Solution: PriorityQueue
- [Instructor] The goal for this code challenge was to work with the priority queue. Now, because I'm working with this queue in two methods, the ProcessOrder method and also in the GetNextOrder method, I created a variable here at the class level called _queue. And it's a priority queue and I specified the value stored in the queue as a decimal and the priority level is set with an integer value. The rules are set here. So here's the code that I wrote to add the items to the queue at the correct priority level. I created a variable called priorityLevel and I initialize that to the value of five. And then I check my first rule, if the order total is greater than or equal to 25 then I set the priority to three. If it's greater than or equal to 75, I set it to one, if it's any other value, then it's five. And then down here I call Enqueue, I pass in the order total that's the decimal value and the priority level. And then in the GetNextOrder there's only one line of code needed, at least the way I solved it, and that's to call _queue.Dequeue. And I just return that value as a decimal. And when I test the code, you can see in the console output that I got the right answer.