Category : queue

I’m trying to make a min priority queue in c++ , but the thing is it contains a struct as it’s data and i don’t know how to sort itslef by cirten value. Here’s an example. #include <queue> struct data { int x, y; float f; data(int x, int y, int f) { this->x = ..

Read more

The code below is inputting a char type. I need help with how to change the input into a numbers (integer) type. #include <stdio.h> #include <iostream> #include <conio.h> using namespace std; typedef char Titem; #define MAXN 3 typedef enum {NOT_OK, OK} Tboolean; typedef struct{ Titem array[MAXN]; int first; int last; int num_of_items; }Tqueue; void initialize_queue(Tqueue ..

Read more

struct customer { long long arrTime; long long cookTime; long long index; }; bool compare( customer& a, customer& b) { return a.arrTime<b.arrTime; } struct Compare1 { bool operator()(customer a,customer b) { return a.cookTime>b.cookTime; } }; struct Compare2 { bool operator()(customer a,customer b) { return a.arrTime>b.arrTime; } }; priority_queue<customer,vector<customer>,Compare2>arrivalList; priority_queue<customer,vector<customer>,Compare1> waitList; This is the code here ..

Read more

I have some code where a thread callback effectively generates some data and writes it to a queue to be consumed by another thread looking something like this auto data_ptr = std::make_shared<DataFrame>(); data_queue_.write(std::move(data_ptr)); I know it was written this way as to avoid copies when reading and writing from the queue. I need to instantiate ..

Read more

I want to create a Queue of Node using template, for the purpose of displaying a BST tree in level order. I create an abstract class Queue a derived of this class called QueueVector, and I have my tree file. I don’t understand why when I create a queue of node the code doesn’t compile ..

Read more

I know we can not iterate easily in STL Queue, but I want to do something like this: void myFun(Node* root) { queue<pair<int, Node*>> myQueue; myQueue.push(make_pair(0, root)); auto it = myQueue.front(); } This works, however, what should I use instead of the auto keyword for the queues? We use something like this for maps: map<int, ..

Read more