Exemplo n.º 1
0
int main(int argc, char** argv) {
    ArrayQueue MevaCua; 
    cout<< "Mida actual de la cua: " << MevaCua.size() << endl; 
    cout<< "Encuem 3 elements a la cua... " << endl; 
    
    MevaCua.enqueue('1');
    MevaCua.enqueue('2'); 
    try{
    MevaCua.enqueue('3'); 
    }
    catch(CuaPlena& e){
            cout << e.what() << endl;
    }
    
    MevaCua.print(); 
    cout << "Cua plena (0:no, 1:si): " << MevaCua.full()<<endl; 
    cout<< "Treiem 1er element de la cua: "<<endl;
    try{
    MevaCua.dequeue();
    }
    catch(CuaBuida& e){
            cout << e.what() << endl;
        }
    MevaCua.print(); 
    cout<< "Treiem 2on element de la cua: " <<endl; 
    MevaCua.dequeue();  
    cout<< "Encuem 2 elements a la cua... " << endl; 
    MevaCua.enqueue('4'); 
    MevaCua.enqueue('5');  
    cout<< "Treiem 3er element de la cua: " <<endl; 
    MevaCua.dequeue(); 
    MevaCua.print(); 
    cout<<"Mida actual de la cua: " << MevaCua.size() << endl; 
    cout<<"Cua buida (0:no, 1:si): " << MevaCua.empty()<<endl;
}
Exemplo n.º 2
0
void print(const ArrayQueue<T> & q)
{
  cout << "capacity = " << q.capacity() << endl
       << "size     = " << q.size() << endl;

  for (int i = 0; i < q.size(); ++i)
    cout << (T) q.front(i) << " ";
  cout << endl ;

  for (int i = 0; i < q.size(); ++i)
    cout << (T) q.rear(i) << " ";
  cout << endl
       << endl;
}
Exemplo n.º 3
0
 /**
  * Obtain the current number of active events. This method is
  * intended for testing and debugging.
  *
  * @return number of active events
  **/
 uint32_t countEvents() const {
     uint32_t cnt = _count;
     for (uint32_t i = 0; i < _queue.size(); ++i) {
         cnt += _queue.peek(i).first;
     }
     return cnt;
 }
Exemplo n.º 4
0
/*
 * Sequence of instructions that the queue object can run.
 */
int main(int argc, char** argv) {
    ArrayQueue mevaCua (MAX_QUEUE);
    cout << "Mida actual de la cua: " << mevaCua.size() << endl;
    cout << "Encuem 3 elements a la cua..." << endl;
    mevaCua.enqueue(1); mevaCua.enqueue(2); mevaCua.enqueue(3);
    mevaCua.print();
    cout << "Cua plena (0: no, 1: si): " << mevaCua.full() << endl;
    cout << "Traiem 1er element de la cua: " << mevaCua.dequeue() << endl;
    mevaCua.print();
    cout << "Traiem 2on element de la cua: " << mevaCua.dequeue() << endl;
    cout << "Encuem 2 elements a la cua... " << endl;
    mevaCua.enqueue(4); mevaCua.enqueue(5);
    cout << "Traiem 3er element de la cua: " << mevaCua.dequeue() << endl;
    cout << "Mida actual de la cua: " << mevaCua.size() << endl;
    mevaCua.print();
    cout << "Cua buida (0:no, 1:si): " << mevaCua.empty() << endl;
    return 0;
}
Exemplo n.º 5
0
 /**
  * Signal the completion of an event. The value passed to this
  * method must be the same as the return value previously obtained
  * from the startEvent method. This method will signal the
  * completion of all pending barriers that were completed by the
  * completion of this event.
  *
  * @param token opaque token identifying the completed event
  **/
 void completeEvent(uint32_t token) {
     if (token == _token) {
         --_count;
         return;
     }
     --_queue.access(_queue.size() - (_token - token)).first;
     while (!_queue.empty() && _queue.front().first == 0) {
         _queue.front().second->completeBarrier();
         _queue.pop();
     }
 }
Exemplo n.º 6
0
 /**
  * Obtain the current number of pending barriers. This method is
  * intended for testing and debugging.
  *
  * @return number of pending barriers
  **/
 uint32_t countBarriers() const {
     return _queue.size();
 }