Free cookie consent management tool by TermsFeed Policy Generator

source: branches/RoutePlanning/HeuristicLab.Algorithms.GraphRouting/3.3/Utilities/PriorityQueueOld.cs @ 9760

Last change on this file since 9760 was 8516, checked in by spimming, 12 years ago

#1894:

  • solution restructured
  • removed obsolete and outdated parts
File size: 1.1 KB
Line 
1
2using System;
3using System.Collections.Generic;
4namespace HeuristicLab.Algorithms.GraphRouting.Utilities {
5  public class PriorityQueueOld<P, T> where P : IComparable {
6    SortedList<Pair<P>, T> list;
7    P dummy;
8
9    public PriorityQueueOld() {
10      list = new SortedList<Pair<P>, T>(new PairComparer<P>());
11    }
12
13    public int Count {
14      get { return list.Count; }
15    }
16
17    public void Enqueue(T item, P priority) {
18      list.Add(new Pair<P>(priority, dummy), item);
19      //count++;
20    }
21
22    public T Dequeue() {
23      T item = list[list.Keys[0]];
24      list.RemoveAt(0);
25      return item;
26    }
27
28    public bool Contains(T item) {
29      return list.ContainsValue(item);
30    }
31
32    public bool Remove(T item) {
33      bool delete = false;
34      KeyValuePair<Pair<P>, T> toDelete = new KeyValuePair<Pair<P>, T>();
35      foreach (var pair in list) {
36        if (pair.Value.Equals(item)) {
37          delete = true;
38          toDelete = pair;
39        }
40      }
41      if (delete) {
42        return list.Remove(toDelete.Key);
43      }
44      return false;
45    }
46
47  }
48}
Note: See TracBrowser for help on using the repository browser.