public MeetingInterval Dequeue()
        {
            var interval = new MeetingInterval()
            {
                Start = Values[0].Start,
                End   = Values[0].End
            };

            Values.RemoveAt(0);
            return(interval);
        }
예제 #2
0
        private static void MinMeetingRooms()
        {
            var meetings = new MeetingInterval[]
            {
                new MeetingInterval {
                    Start = 0, End = 30
                },
                new MeetingInterval {
                    Start = 5, End = 10
                },
                new MeetingInterval {
                    Start = 15, End = 20
                },
                new MeetingInterval {
                    Start = 10, End = 20
                }
            };

            Console.WriteLine($"Min meeting rooms: {Helpers.FindMinMeetingRooms(meetings)}");
        }
예제 #3
0
        internal static int FindMinMeetingRooms(MeetingInterval[] meetings)
        {
            Array.Sort <MeetingInterval>(meetings, (a, b) => a.Start - b.Start);
            SimplePriorityQueue q = new SimplePriorityQueue();

            q.Enqueue(meetings[0]);
            for (int i = 1; i < meetings.Length; i++)
            {
                MeetingInterval current  = meetings[i];
                MeetingInterval earliest = q.Dequeue();
                if (current.Start >= earliest.End)
                {
                    earliest.End = current.End;
                }
                else
                {
                    q.Enqueue(current);
                }

                q.Enqueue(earliest);
            }

            return(q.Count);
        }
 public void Enqueue(MeetingInterval meeting)
 {
     Values.Add(meeting);
     Values.Sort((a, b) => a.End - b.End);
 }