fork download
  1. // Naomi Jones
  2. // Survey, Summer 2025
  3. // July 6, 2025
  4. // Assignment 6 - 4 C# Queue
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8.  
  9. class QueueSample
  10. {
  11. public static void Main()
  12. {
  13. // Creates a queue of strings that holds operas.
  14. Queue<string> operaCollection = new Queue<string> ();
  15.  
  16. // Adds operas to the queue.
  17. operaCollection.Enqueue ("Don Giovanni");
  18. operaCollection.Enqueue ("Un Ballo in Maschera");
  19. operaCollection.Enqueue ("Aida");
  20. operaCollection.Enqueue ("Der fliegende Hollander");
  21. operaCollection.Enqueue ("Gotterdammerung");
  22. operaCollection.Enqueue ("Turandot");
  23.  
  24. // Print the operas in the queue.
  25. Console.WriteLine("Operas in my Spotify queue on 7/5/2025: ");
  26. foreach (string opera in operaCollection)
  27. {
  28. Console.WriteLine(opera);
  29. }
  30.  
  31. // We listened to Don Giovanni on 07/05/2025 - removed from the queue.
  32. operaCollection.Dequeue ();
  33.  
  34. // Current queue looks like this on 07/06/2025.
  35. Console.WriteLine("\nOperas left in my Spotify queue on 7/6/2025 after listening to Don Giovanni:");
  36. foreach (string opera in operaCollection)
  37. {
  38. Console.WriteLine(opera);
  39. }
  40.  
  41. // Print number of remaining operas in my Spotify queue.
  42. Console.WriteLine("\nNumber of operas in my Spotify queue on 7/6/2025 " + operaCollection.Count);
  43.  
  44. // Prints opera next in the queue.
  45. Console.WriteLine("\nThe next opera in my Spotify queue on 7/5/2025 is " + operaCollection.Peek());
  46.  
  47. } // main
  48.  
  49. } // QueueSample class
  50.  
Success #stdin #stdout 0.07s 26972KB
stdin
Standard input is empty
stdout
Operas in my Spotify queue on 7/5/2025: 
Don Giovanni
Un Ballo in Maschera
Aida
Der fliegende Hollander
Gotterdammerung
Turandot

Operas left in my Spotify queue on 7/6/2025 after listening to Don Giovanni:
Un Ballo in Maschera
Aida
Der fliegende Hollander
Gotterdammerung
Turandot

Number of operas in my Spotify queue on 7/6/2025 5

The next opera in my Spotify queue on 7/5/2025 is Un Ballo in Maschera