Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #ifndef QUEUE_H
- #define QUEUE_H
- #include <iostream>
- using namespace std;
- template <typename Type> class Cell{
- public:
- unsigned int priority;
- Type data;
- Cell* next;
- Cell() : next(nullptr) {}
- Cell(Type arg) : data(arg), next(nullptr) {}
- };
- template <typename Type> class queue {
- public:
- queue() : m_Head(nullptr),
- m_size(0) {}
- void push(Type arg, unsigned int p){
- Cell *tmp = new Cell<Type>(arg);
- tmp->priority = p;
- tmp->next - m_Head;
- m_Head = tmp;
- }
- pop() {
- unsigned int max = 0;
- unsigned int index = 0;
- unsigned int i = 0;
- Cell<Type> *current = m_Head;
- while (current->next != nullptr){
- if (current->priority > max){
- max = current->priority;
- index = i;
- }
- i++;
- current = current->next;
- }
- currenr = m_Head;
- Cell<Type> *del = m_Head;
- if (index == 0){
- if (current_next->next != nullptr) {
- del = current;
- current->next = current->next->next;
- }
- else {
- del = current;
- }
- else {
- for (unsigned int j = 0; j < index; j++) {
- if (j == index - 1)
- break;
- del = current->next;
- current = current->next;
- }
- if (current->next->next != nullptr){
- del = current->next;
- current->next = current->next->next;
- }
- else
- del = current->next;
- }
- }
- m_size--;
- return del->data;
- }
- private:
- Cell *m_Head;
- unsigned int m_size;
- unsigned int m_currentSize;
- };
- #endif //QUEUE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement