Пример #1
0
        static void Main(string[] args)
        {
            // Task 11: Write a class Student, that has three fields: name (String), age(Integer) and paidSemesterOnline(Boolean).
            // When in a queue the students who paid online are with higher priority than those who are about to pay the semester.
            // Write a program which, given a queue of students, determines whose turn it is. Hint: use priority queue.

            PriorityQueue pqueue = new PriorityQueue();
            for (int i = 1; i <= 10; i++)
            {
                Random r = new Random();
                bool paidOnline;
                int priority;

                // let's assume every 4th student has paid online (Mimi and Ivo in this case)
                if (i % 4 == 0)
                {
                    paidOnline = true;
                    priority = 1;
                }
                else
                {
                    paidOnline = false;
                    priority = 10;
                }

                Student student = new Student(names[i - 1], r.Next(18, 120), paidOnline);
                pqueue.Enqueue(priority, student);
            }

            while (!pqueue.IsEmpty)
            {
                Student student = pqueue.Dequeue();
                Console.WriteLine(student);
            }
        }
Пример #2
0
 public void Enqueue(int priority, Student value)
 {
     Queue<Student> q;
     if (!list.TryGetValue(priority, out q))
     {
         q = new Queue<Student>();
         list.Add(priority, q);
     }
     q.Enqueue(value);
 }