Priority Queues with C#: Listing 2.

The Employee class.

public class Employee : IComparable <Employee >
{
  public string lastName;
  public double priority; // Smaller values are higher priority

  public Employee(string lastName, double priority)
  {
    this.lastName = lastName;
    this.priority = priority;
  }

  public override string ToString()
  {
    return "(" + lastName + ", " + priority.ToString("F1") + ")";
  }

  public int CompareTo(Employee other)
  {
    if (this.priority  < other.priority) return -1;
    else if (this.priority  > other.priority) return 1;
    else return 0;
  }
}

About the Author

Dr. James McCaffrey works for Microsoft Research in Redmond, WA. James has worked on several key Microsoft products such as Internet Explorer and Bing. James can be reached at jamccaff@microsoft.com.