/* Author : Rick van der Zwet * S-number : 0433373 * Version : $Id: queue.cc 234 2007-09-17 18:56:11Z rick $ * Copyright : FreeBSD Licence */ #include "queue.h" /* * Class Queue general functions */ bool Queue::IsEmpty (void) { return( lijst->IsEmpty() ); } Queue::Queue (void) { lijst = new List; } Queue::~Queue (void) { delete lijst; } /* Insert value to array while keeps the array sorted by size * from Small to Big * XXX: Not very effient on large lists */ void Queue::SortBySize (const int item) { //if list empty no magic needs to be done if ( lijst->IsEmpty() ) { lijst->Insert(item); return; } //Start looping trough the list lijst->GoToBegin(); while ( not lijst->IsEnd() ) { if ( lijst->Get() > item ) { //smaller, add before lijst->Insert(item); return; } lijst->GoToNext(); } //hitting this stage is the number depends on the last number if ( lijst->Get() > item ) { //smaller lijst->Insert(item); } else { //bigger lijst->Append(item); } } /* Get last value from array and remove it * Return 0 if none exists */ int Queue::Pop (void) { int tmpvalue; lijst->GoToEnd(); tmpvalue = lijst->Get(); lijst->Delete(); return(tmpvalue); } /* Get first value from array and remove it * Return 0 if none exists */ int Queue::Shift (void) { int tmpvalue; lijst->GoToBegin(); tmpvalue = lijst->Get(); lijst->Delete(); return(tmpvalue); } /* Prepent the value to the front of the list */ void Queue::Unshift (const int item) { lijst->GoToBegin(); lijst->Insert(item); } /* Append the value to the end of the list */ void Queue::Push (const int item) { lijst->GoToEnd(); lijst->Append(item); } /* * Class Lifo functions */ /* * Class MinQ functions */ /* * Class MaxQ functions */