// Naomi Jones
// Survey, Summer 2025
// July 6, 2025
// Assignment 6 - 5 C# Linked List
using System;
using System.Collections.Generic;
public class AdvancedLinkedList {
// OperaItem class to hold opera names and comments.
public class OperaItem
{
// Private fields to store values.
private string _name;
private string _comment;
// Constructor to initialize opera items.
public OperaItem (string name, string comment)
{
_name = name;
_comment = comment;
}
// Properties for opera names and comments.
public string Name
{
get {return _name;}
set {_name = value;}
}
public string Comment
{
get {return _comment;}
set {_comment = value;}
}
} // class OperaItem
public static void Main() {
// Create a new LinkedList object.
LinkedList<OperaItem> operaList = new LinkedList<OperaItem>( );
// Create OperaItem objects to add to the linked list.
OperaItem i1 = new OperaItem ("Aida", "My spouse's favorite opera of all time!");
OperaItem i2 = new OperaItem ("Don Giovanni", "Best opera of all time!!!");
OperaItem i3 = new OperaItem ("Un Ballo in Maschera", "Second best opera of all time!");
OperaItem i4 = new OperaItem ("Der fliegende Holländer", "It's not bad.");
OperaItem i5 = new OperaItem ("Gotterdammerung", "Great music...if you're still awake!");
OperaItem i6 = new OperaItem ("Turandot", "Unfinished by composer. It's okay.");
// Add items to the linked list by preference.
operaList.AddFirst (i1);
operaList.AddFirst (i2);
operaList.AddBefore (operaList.Find (i1), i3); // Moves after i1.
operaList.AddAfter (operaList.Find (i1), i4); // Moves before i1.
operaList.AddLast (i5);
operaList.AddLast (i6);
Console.WriteLine ("\nMy personal ranking of operas:");
// Displays all items.
foreach (OperaItem opera in operaList)
{
Console.WriteLine (opera.Name + " : " + opera.Comment);
}
// Removes the last node.
if (operaList.Last != null)
{
operaList.RemoveLast();
}
else
{
Console.WriteLine("List is empty. Cannot remove an opera.");
}
Console.WriteLine("\nRemaining list after removing the last opera:");
foreach (OperaItem opera in operaList) // Prints remaining operas.
{
Console.WriteLine(opera.Name);
}
// Removes the first node.
if (operaList.First != null)
{
operaList.RemoveFirst();
}
else
{
Console.WriteLine("List is empty. Cannot remove an opera.");
}
Console.WriteLine("\nRemaining list after removing the first opera:");
foreach (OperaItem opera in operaList) // Prints remaining operas.
{
Console.WriteLine(opera.Name);
}
} // Main
} // AdvancedLinkedList