#include <iostream>
#include <random>
#include <queue>
#include <list>
using namespace std;
struct Node
{
int nodeVal;
list<int> valuesInRange;
};
int main()
{
default_random_engine generator;
int a = 0, b = 100;
uniform_int_distribution<int> distribution(a, b);
int N;
cout << "Enter the N(more than 10): ";
cin >> N;
int i;
int values[N];
Node nodes[5];
priority_queue<Node> myQ;
for(i = 0; i < N; i++)
{
values[i] = distribution(generator);
if(i < 5)
{
nodes[i].nodeVal = values[i];
myQ.push(nodes[i]);
}
}
for(i = 0; i < 5; i++)
{
nodes[i] = myQ.top();
myQ.pop();
}
int j;
for(j = 5; j < N; j++)
{
if(values[j] <= nodes[0].nodeVal)
nodes[0].valuesInRange.push_back(values[j]);
else if(values[j] > nodes[0].nodeVal && values[j] <= nodes[1].nodeVal)
nodes[1].valuesInRange.push_back(values[j]);
else if(values[j] > nodes[1].nodeVal && values[j] <= nodes[2].nodeVal)
nodes[2].valuesInRange.push_back(values[j]);
else if(values[j] > nodes[2].nodeVal && values[j] <= nodes[3].nodeVal)
nodes[3].valuesInRange.push_back(values[j]);
else if(values[j] > nodes[3].nodeVal && values[j] <= nodes[4].nodeVal)
nodes[4].valuesInRange.push_back(values[j]);
}
return 0;
}
Comments
Leave a comment