Last change
on this file since 253 was 2, checked in by Rick van der Zwet, 15 years ago |
Initial import of data of old repository ('data') worth keeping (e.g. tracking
means of URL access statistics)
|
File size:
1.9 KB
|
Rev | Line | |
---|
[2] | 1 | /* Author : Rick van der Zwet
|
---|
| 2 | * S-number : 0433373
|
---|
| 3 | * Version : $Id: queue.cc 234 2007-09-17 18:56:11Z rick $
|
---|
| 4 | * Copyright : FreeBSD Licence
|
---|
| 5 | */
|
---|
| 6 |
|
---|
| 7 |
|
---|
| 8 | #include "queue.h"
|
---|
| 9 |
|
---|
| 10 | /*
|
---|
| 11 | * Class Queue general functions
|
---|
| 12 | */
|
---|
| 13 |
|
---|
| 14 | bool Queue::IsEmpty (void)
|
---|
| 15 | {
|
---|
| 16 | return( lijst->IsEmpty() );
|
---|
| 17 | }
|
---|
| 18 |
|
---|
| 19 | Queue::Queue (void)
|
---|
| 20 | {
|
---|
| 21 | lijst = new List;
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | Queue::~Queue (void)
|
---|
| 25 | {
|
---|
| 26 | delete lijst;
|
---|
| 27 | }
|
---|
| 28 |
|
---|
| 29 | /* Insert value to array while keeps the array sorted by size
|
---|
| 30 | * from Small to Big
|
---|
| 31 | * XXX: Not very effient on large lists
|
---|
| 32 | */
|
---|
| 33 | void Queue::SortBySize (const int item)
|
---|
| 34 | {
|
---|
| 35 | //if list empty no magic needs to be done
|
---|
| 36 | if ( lijst->IsEmpty() ) {
|
---|
| 37 | lijst->Insert(item);
|
---|
| 38 | return;
|
---|
| 39 | }
|
---|
| 40 |
|
---|
| 41 | //Start looping trough the list
|
---|
| 42 | lijst->GoToBegin();
|
---|
| 43 | while ( not lijst->IsEnd() )
|
---|
| 44 | {
|
---|
| 45 | if ( lijst->Get() > item )
|
---|
| 46 | {
|
---|
| 47 | //smaller, add before
|
---|
| 48 | lijst->Insert(item);
|
---|
| 49 | return;
|
---|
| 50 | }
|
---|
| 51 | lijst->GoToNext();
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | //hitting this stage is the number depends on the last number
|
---|
| 55 | if ( lijst->Get() > item )
|
---|
| 56 | {
|
---|
| 57 | //smaller
|
---|
| 58 | lijst->Insert(item);
|
---|
| 59 | }
|
---|
| 60 | else {
|
---|
| 61 | //bigger
|
---|
| 62 | lijst->Append(item);
|
---|
| 63 | }
|
---|
| 64 | }
|
---|
| 65 |
|
---|
| 66 | /* Get last value from array and remove it
|
---|
| 67 | * Return 0 if none exists
|
---|
| 68 | */
|
---|
| 69 | int Queue::Pop (void)
|
---|
| 70 | {
|
---|
| 71 | int tmpvalue;
|
---|
| 72 | lijst->GoToEnd();
|
---|
| 73 | tmpvalue = lijst->Get();
|
---|
| 74 | lijst->Delete();
|
---|
| 75 | return(tmpvalue);
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | /* Get first value from array and remove it
|
---|
| 79 | * Return 0 if none exists
|
---|
| 80 | */
|
---|
| 81 | int Queue::Shift (void)
|
---|
| 82 | {
|
---|
| 83 | int tmpvalue;
|
---|
| 84 | lijst->GoToBegin();
|
---|
| 85 | tmpvalue = lijst->Get();
|
---|
| 86 | lijst->Delete();
|
---|
| 87 | return(tmpvalue);
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | /* Prepent the value to the front of the list */
|
---|
| 91 | void Queue::Unshift (const int item)
|
---|
| 92 | {
|
---|
| 93 | lijst->GoToBegin();
|
---|
| 94 | lijst->Insert(item);
|
---|
| 95 | }
|
---|
| 96 | /* Append the value to the end of the list */
|
---|
| 97 | void Queue::Push (const int item)
|
---|
| 98 | {
|
---|
| 99 | lijst->GoToEnd();
|
---|
| 100 | lijst->Append(item);
|
---|
| 101 | }
|
---|
| 102 |
|
---|
| 103 |
|
---|
| 104 |
|
---|
| 105 | /*
|
---|
| 106 | * Class Lifo functions
|
---|
| 107 | */
|
---|
| 108 |
|
---|
| 109 |
|
---|
| 110 |
|
---|
| 111 | /*
|
---|
| 112 | * Class MinQ functions
|
---|
| 113 | */
|
---|
| 114 |
|
---|
| 115 |
|
---|
| 116 |
|
---|
| 117 | /*
|
---|
| 118 | * Class MaxQ functions
|
---|
| 119 | */
|
---|
Note:
See
TracBrowser
for help on using the repository browser.