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, Wash. He has worked on several Microsoft products including Azure and Bing. James can be reached at [email protected].

comments powered by Disqus

Featured

Subscribe on YouTube