I have a queue class code is given below:
struct ListNode
{
ListNode(int value);
int value;
ListNode* next;
};
ListNode::ListNode(int value): value(value), next(nullptr) {}
public class queue
{
public:
queue();
~queue();
bool Empty() const;
int Next() const;
void Enqueue(int value);
void Dequeue();
void DisplayAll() const;
int getP() const;
private:
// Disable copying to keep the example simple
queue(queue const& obj);
ListNode* head;
ListNode* tail;
gcroot<String^> name; // Added this
};
queue::queue():head(nullptr), tail(nullptr) {}
queue::~queue()
{
while (head != nullptr)
{
Dequeue();
}
}
bool queue::Empty() const
{
return head == nullptr;
}
int queue::Next() const
{
return head->value;
}
void queue::Enqueue(int value)
{
if (head == nullptr)
{
head = tail = new ListNode(value);
}
else
{
tail->next = new ListNode(value);
tail = tail->next;
}
}
void queue::Dequeue()
{
ListNode* temp = head->next;
delete head;
head = temp;
}
void queue::DisplayAll() const
{
for (ListNode* p = head; p; p = p->next)
{
Console::WriteLine("the element is {0}", p->value);
}
}
I need some help regarding queues operation, which I already have made. To help explain the problem you need to look at this code and the queue operations given in the above posted code.
if(Analysis[no].priority==1)
cat1->Enqueue(no);
else if(Analysis[no].priority==2)
cat2->Enqueue(no);
else if(Analysis[no].priority==3)
cat3->Enqueue(no);
while(!(cat1->Empty()))
{
p= cat1->Next();
TimDep= currtime+expntl();
slist->Add(TimDep,"D");
Analysis[p].TEsf=TimDep;
}
consider we have 3 queues cat1, cat2, cat 3. I want to insert items with pririty 1,2,3 respectively. which I am doing via this code. Now I want to process these inserted messages(or items "no"). First I want to process all messages in queue "cat1" and dequeue them one by one untill its empty, then it should move to "cat2" and same process and then to "cat3". I am stuck in the process of iterating through each element of queue how can I do that? can you help me please!!!!