Пример #1
0
int main(int argc, char **argv)
{
  // Generates a vector of pairs, with a size given by the first argument. Each element is added to a priority queue.
  if (argc != 2)
    {
      cout << "Usage: " << argv[0] << " <number of pairs to generate>" << endl;
      return - 1;
    }

  int count = atoi(argv[1]);
  cout << "Creating priority queue of size " << count << endl;
  std::vector<C_FLOAT64> invec;
  CIndexedPriorityQueue pq;
  CRandom *rand = new CRandom(1);
  C_FLOAT64 rndval;
  cout << "Input vector:\n";

  for (int i = 0; i < count; i++)
    {
      rndval = rand->getUniformRandom();
      invec.push_back(rndval);
      cout << "element " << i << ":" << rndval << endl;
      pq.pushPair(i, invec[i]);
    }

  cout << "Building heap\n";
  pq.buildHeap();
  cout << "Done building heap\n";
  // Display the priority queue
  cout << "\nPriority Queue:\n";

  for (int i = 0; i < count; i++)
    {
      cout << "Queue: ";

      for (int j = 0; j < count; j++) cout << " " << j << "-" << pq[j];

      cout << endl;
      cout << "Position: " << i;
      cout << " Index = " << pq.topIndex();
      cout << " Key = " << pq.topKey() << endl;
      pq.updateNode(pq.topIndex(), 10000000);
    }

  return 0;
}