fork download
  1. using System;
  2. using System.Collections.Generic;
  3.  
  4. public class GenericCollection
  5. {
  6. public class KpopGroup
  7. {
  8. public KpopGroup(string name, string comment)
  9. {
  10. _name = name;
  11. _comment = comment;
  12. }
  13.  
  14. private string _name = "";
  15. private string _comment = "";
  16.  
  17. public string Name
  18. {
  19. get { return _name; }
  20. set { _name = value; }
  21. }
  22.  
  23. public string Comment
  24. {
  25. get { return _comment; }
  26. set { _comment = value; }
  27. }
  28. } // class KpopGroup
  29.  
  30. public static void Main()
  31. {
  32. // Create a new LinkedList object.
  33. LinkedList<KpopGroup> groupList = new LinkedList<KpopGroup>();
  34.  
  35. // Create KpopGroup objects to add to the linked list.
  36. KpopGroup g1 = new KpopGroup("BLACKPINK", "The most popular KPop female group right now. Consists of 4 members.");
  37. KpopGroup g2 = new KpopGroup("Kiss of Life", "Sexy vibe with amazing style. Consists of 4 members.");
  38. KpopGroup g3 = new KpopGroup("Stray Kids", "Write and produce their own songs. Mind-blowing music videos and dance choreography. Consists of 8 members.");
  39. KpopGroup g4 = new KpopGroup("BABYMONSTER", "Younger female group with monster-level talents. Consists of 7 members.");
  40. KpopGroup g5 = new KpopGroup("TREASURE", "Immensely talented male group that needs more promotion from their company. Consists of 10 members.");
  41.  
  42. // Add the items to the linked list
  43. groupList.AddFirst(g1); // BLACKPINK
  44. groupList.AddFirst(g2); // Kiss of Life before BLACKPINK
  45. groupList.AddBefore(groupList.Find(g1), g3); // Stray Kids before BLACKPINK
  46. groupList.AddAfter(groupList.Find(g1), g4); // BABYMONSTER after BLACKPINK
  47. groupList.AddLast(g5); // TREASURE at the end
  48.  
  49. Console.WriteLine("\nMy Favorite KPop Groups and Their Comments:\n");
  50.  
  51. // Display all items
  52. foreach (KpopGroup grp in groupList)
  53. {
  54. Console.WriteLine(grp.Name + " : " + grp.Comment);
  55. }
  56.  
  57. Console.WriteLine("\nDisplaying the second group in the ranking:\n");
  58. Console.WriteLine("groupList.First.Next.Value.Name == " +
  59. groupList.First.Next.Value.Name);
  60.  
  61. Console.WriteLine("\nDisplaying the next-to-last group in the ranking:\n");
  62. Console.WriteLine("groupList.Last.Previous.Value.Name == " +
  63. groupList.Last.Previous.Value.Name);
  64. }
  65. }
Success #stdin #stdout 0.03s 27628KB
stdin
Standard input is empty
stdout
My Favorite KPop Groups and Their Comments:

Kiss of Life : Sexy vibe with amazing style. Consists of 4 members.
Stray Kids : Write and produce their own songs. Mind-blowing music videos and dance choreography. Consists of 8 members.
BLACKPINK : The most popular KPop female group right now. Consists of 4 members.
BABYMONSTER : Younger female group with monster-level talents. Consists of 7 members.
TREASURE : Immensely talented male group that needs more promotion from their company. Consists of 10 members.

Displaying the second group in the ranking:

groupList.First.Next.Value.Name == Stray Kids

Displaying the next-to-last group in the ranking:

groupList.Last.Previous.Value.Name == BABYMONSTER