skinshape
skinshape

Reputation: 133

How can I make a two dimensional linked list in C#?

My task is to make a program for company about room reservation. First I have to make a linked list for the rooms. Each room also contain a linked list for the meetings that can be reserved for that room. The user can place meetings( with a start and end time) with a method.

I can NOT use the built-in LinkedList in C#, I HAVE to create that also. I won't post the methods like insert/remove/etc., just the basic LinkedList

{
class ListNode<T>
{
    public T content;
    public ListNode<T> next;
}

class LinkedList<T>
{
    class ListNode 
    {
        public T content;
        public ListNode<T> next;
    }
    ListNode<T> head;   
    }

}

My questions:

Could I create this "linkedlist in linkedlist" with a single two-dimensional linkedlist?

If the answer is yes, then how? If it's no then what are my options?

Upvotes: 2

Views: 431

Answers (1)

Eric J.
Eric J.

Reputation: 150138

It seems easier to think of this as a hierarchy of linked lists, not really a two-dimensional linked list.

You can model the concepts of a room and a reservation something like

class Reservation
{
    public string Who { get; set; }
    public DateTime Start { get; set; }
    public DateTime End { get; set; }
}

class Room
{
    public int Number { get; set; }
    public LinkedList<Reservation> Reservations { get; set; }
}

LinkedList<Room> rooms = new LinkedList<Room>();

Upvotes: 1

Related Questions