fork download
  1. // Naomi Jones
  2. // Survey, Summer 2025
  3. // July 6, 2025
  4. // Assignment 6 - 5 C# Linked List
  5.  
  6. using System;
  7. using System.Collections.Generic;
  8.  
  9. public class AdvancedLinkedList {
  10.  
  11. // OperaItem class to hold opera names and comments.
  12. public class OperaItem
  13. {
  14. // Private fields to store values.
  15. private string _name;
  16. private string _comment;
  17.  
  18. // Constructor to initialize opera items.
  19. public OperaItem (string name, string comment)
  20. {
  21. _name = name;
  22. _comment = comment;
  23. }
  24.  
  25. // Properties for opera names and comments.
  26. public string Name
  27. {
  28. get {return _name;}
  29. set {_name = value;}
  30. }
  31.  
  32. public string Comment
  33. {
  34. get {return _comment;}
  35. set {_comment = value;}
  36. }
  37. } // class OperaItem
  38.  
  39.  
  40. public static void Main() {
  41.  
  42. // Create a new LinkedList object.
  43. LinkedList<OperaItem> operaList = new LinkedList<OperaItem>( );
  44.  
  45. // Create OperaItem objects to add to the linked list.
  46. OperaItem i1 = new OperaItem ("Aida", "My spouse's favorite opera of all time!");
  47. OperaItem i2 = new OperaItem ("Don Giovanni", "Best opera of all time!!!");
  48. OperaItem i3 = new OperaItem ("Un Ballo in Maschera", "Second best opera of all time!");
  49. OperaItem i4 = new OperaItem ("Der fliegende Holländer", "It's not bad.");
  50. OperaItem i5 = new OperaItem ("Gotterdammerung", "Great music...if you're still awake!");
  51. OperaItem i6 = new OperaItem ("Turandot", "Unfinished by composer. It's okay.");
  52.  
  53. // Add items to the linked list by preference.
  54. operaList.AddFirst (i1);
  55. operaList.AddFirst (i2);
  56. operaList.AddBefore (operaList.Find (i1), i3);
  57. operaList.AddAfter (operaList.Find (i1), i4);
  58. operaList.AddLast (i5);
  59. operaList.AddLast (i6);
  60.  
  61. Console.WriteLine ("\nMy personal ranking of operas:\n");
  62.  
  63. // Display all items.
  64. foreach (OperaItem opera in operaList)
  65. {
  66. Console.WriteLine (opera.Name + " : " + opera.Comment);
  67. }
  68.  
  69. } // Main
  70.  
  71. } // AdvancedLinkedList
Success #stdin #stdout 0.06s 29052KB
stdin
Standard input is empty
stdout
My personal ranking of operas:

Don Giovanni : Best opera of all time!!!
Un Ballo in Maschera : Second best opera of all time!
Aida : My spouse's favorite opera of all time!
Der fliegende Holländer : It's not bad.
Gotterdammerung : Great music...if you're still awake!
Turandot : Unfinished by composer. It's okay.