Advertisement
Guest User

Untitled

a guest
May 24th, 2015
195
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.45 KB | None | 0 0
  1. #ifndef QUEUE_H
  2. #define QUEUE_H
  3.  
  4. #include <iostream>
  5. using namespace std;
  6.  
  7. template <typename Type> class Cell{
  8. public:
  9.     unsigned int priority;
  10.     Type data;
  11.     Cell* next;
  12.  
  13.     Cell() : next(nullptr) {}
  14.     Cell(Type arg) : data(arg), next(nullptr) {}
  15. };
  16.  
  17. template <typename Type> class queue {
  18. public:
  19.     queue() : m_Head(nullptr),
  20.         m_size(0) {}
  21.  
  22.     void push(Type arg, unsigned int p){
  23.         Cell *tmp = new Cell<Type>(arg);
  24.         tmp->priority = p;
  25.         tmp->next - m_Head;
  26.         m_Head = tmp;
  27.     }
  28.  
  29.     pop() {
  30.         unsigned int max = 0;
  31.         unsigned int index = 0;
  32.         unsigned int i = 0;
  33.         Cell<Type> *current = m_Head;
  34.  
  35.         while (current->next != nullptr){
  36.             if (current->priority > max){
  37.                 max = current->priority;
  38.                 index = i;
  39.             }
  40.             i++;
  41.             current = current->next;
  42.         }
  43.  
  44.         currenr = m_Head;
  45.         Cell<Type> *del = m_Head;
  46.  
  47.  
  48.         if (index == 0){
  49.             if (current_next->next != nullptr) {
  50.                 del = current;
  51.                 current->next = current->next->next;
  52.             }
  53.             else {
  54.                 del = current;
  55.             }
  56.         else {
  57.             for (unsigned int j = 0; j < index; j++) {
  58.                 if (j == index - 1)
  59.                     break;
  60.                 del = current->next;
  61.                 current = current->next;
  62.             }
  63.  
  64.             if (current->next->next != nullptr){
  65.                 del = current->next;
  66.                 current->next = current->next->next;
  67.             }
  68.             else
  69.                 del = current->next;
  70.  
  71.         }
  72.  
  73.  
  74.         }
  75.  
  76.         m_size--;
  77.         return del->data;
  78.     }
  79.  
  80.  
  81. private:
  82.     Cell *m_Head;
  83.     unsigned int m_size;
  84.     unsigned int m_currentSize;
  85.  
  86.  
  87. };
  88.  
  89.  
  90. #endif  //QUEUE_H
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement