https://exceptionnotfound.net/bite-size-dotnet-6-priorityqueue/
Created
October 29, 2021 08:59
-
-
Save MarioBinder/4a9e88d35db489445d1959f4a8d384e1 to your computer and use it in GitHub Desktop.
PriorityQueue Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var tvShows = new PriorityQueue<string, ShowRating>(); | |
tvShows.Enqueue("Modern Family", ShowRating.Good); | |
tvShows.Enqueue("Ted Lasso", ShowRating.Amazing); | |
tvShows.Enqueue("MasterChef", ShowRating.Good); | |
tvShows.Enqueue("Breaking Bad", ShowRating.Transcendant); | |
tvShows.Enqueue("Happy Endings", ShowRating.Amazing); | |
tvShows.Enqueue("Game of Thrones (Seasons 1-6)", ShowRating.Amazing); | |
tvShows.Enqueue("Game of Thrones (Seasons 7-8)", ShowRating.OK); | |
tvShows.Enqueue("How to Get Away with Murder", ShowRating.Good); | |
tvShows.Enqueue("Hell's Kitchen", ShowRating.OK); | |
Console.WriteLine("What should we watch?"); | |
var currentShow = tvShows.Dequeue(); | |
//The shows will be dequeued in order of the ShowRating value | |
Console.WriteLine($"Let's try {currentShow}!"); | |
while(tvShows.Count > 0) | |
{ | |
Console.WriteLine($"If not, let's try {tvShows.Dequeue()}."); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public enum ShowRating | |
{ | |
Transcendant, //1 | |
Amazing, //2 | |
Good, //3 | |
OK //4 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment