0
0
C Sharp (C#)programming~30 mins

LinkedList usage in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
LinkedList usage
📖 Scenario: You are managing a waiting list for a small cafe. Customers arrive and are added to the list in order. Sometimes, customers leave the list before being served.
🎯 Goal: You will create a linked list to hold customer names, add customers to the list, remove a customer who leaves early, and finally display the current waiting list.
📋 What You'll Learn
Use the LinkedList<string> class
Add customers to the linked list using AddLast
Remove a specific customer using Remove
Iterate over the linked list to print all customer names
💡 Why This Matters
🌍 Real World
Linked lists are useful when you need to add or remove items quickly from the start or end of a list, like managing queues or waiting lists.
💼 Career
Understanding linked lists helps in software development roles that involve data structures, improving your ability to write efficient and flexible code.
Progress0 / 4 steps
1
Create the linked list
Create a LinkedList<string> called waitingList and add these customers in order using AddLast: "Alice", "Bob", "Charlie".
C Sharp (C#)
Need a hint?

Use LinkedList<string> waitingList = new LinkedList<string>(); to create the list. Then add each name with waitingList.AddLast(name);.

2
Remove a customer
Create a variable called customerToRemove and set it to "Bob". Then remove customerToRemove from waitingList using the Remove method.
C Sharp (C#)
Need a hint?

Set string customerToRemove = "Bob"; and then call waitingList.Remove(customerToRemove);.

3
Iterate over the linked list
Use a foreach loop with variable customer to go through waitingList and add each customer to a new List<string> called currentCustomers.
C Sharp (C#)
Need a hint?

Create List<string> currentCustomers = new List<string>(); then use foreach (string customer in waitingList) to add each customer.

4
Print the current waiting list
Use a foreach loop with variable customer to print each name in currentCustomers on its own line using Console.WriteLine.
C Sharp (C#)
Need a hint?

Use foreach (string customer in currentCustomers) and inside the loop write Console.WriteLine(customer);.