Skip to content

Instantly share code, notes, and snippets.

@MarioBinder
Created October 29, 2021 08:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarioBinder/4a9e88d35db489445d1959f4a8d384e1 to your computer and use it in GitHub Desktop.
Save MarioBinder/4a9e88d35db489445d1959f4a8d384e1 to your computer and use it in GitHub Desktop.
PriorityQueue Example
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()}.");
}
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