Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
2 | pj | 1 | /* |
2 | * Copyright 1995, Brown University, Providence, RI |
||
3 | * |
||
4 | * Permission to use and modify this software and its documentation for |
||
5 | * any purpose other than its incorporation into a commercial product is |
||
6 | * hereby granted without fee. Permission to copy and distribute this |
||
7 | * software and its documentation only for non-commercial use is also |
||
8 | * granted without fee, provided, however, that the above copyright notice |
||
9 | * appear in all copies, that both that copyright notice and this permission |
||
10 | * notice appear in supporting documentation, that the name of Brown |
||
11 | * University not be used in advertising or publicity pertaining to |
||
12 | * distribution of the software without specific, written prior permission, |
||
13 | * and that the person doing the distribution notify Brown University of |
||
14 | * such distributions outside of his or her organization. Brown University |
||
15 | * makes no representations about the suitability of this software for |
||
16 | * any purpose. It is provided "as is" without express or implied warranty. |
||
17 | * Brown University requests notification of any modifications to this |
||
18 | * software or its documentation. |
||
19 | * |
||
20 | * Send the following redistribution information: |
||
21 | * |
||
22 | * Name: |
||
23 | * Organization: |
||
24 | * Address (postal and/or electronic): |
||
25 | * |
||
26 | * To: |
||
27 | * Software Librarian |
||
28 | * Computer Science Department, Box 1910 |
||
29 | * Brown University |
||
30 | * Providence, RI 02912 |
||
31 | * |
||
32 | * or |
||
33 | * |
||
34 | * brusd@cs.brown.edu |
||
35 | * |
||
36 | * We will acknowledge all electronic notifications. |
||
37 | */ |
||
38 | #include "queue_int.H" |
||
39 | |||
40 | QUEUEint::QUEUEint() |
||
41 | : headOfList(NULL), |
||
42 | tailOfList(NULL) |
||
43 | { |
||
44 | } |
||
45 | |||
46 | |||
47 | //Deconstructor |
||
48 | QUEUEint::~QUEUEint() |
||
49 | { |
||
50 | //Dequeue all the nodes |
||
51 | for (int result=1,tmp;result;tmp=deQueue(result)) { |
||
52 | } |
||
53 | |||
54 | } |
||
55 | |||
56 | int QUEUEint::deQueue(int &result) |
||
57 | { |
||
58 | if (!tailOfList) { |
||
59 | result=0; |
||
60 | return 0; |
||
61 | } else result=1; |
||
62 | |||
63 | int retVal = headOfList->data; |
||
64 | |||
65 | //save node to delete |
||
66 | Item *deleteNode=headOfList; |
||
67 | |||
68 | // only one node on list? |
||
69 | if (tailOfList==headOfList) { |
||
70 | tailOfList=headOfList=NULL; |
||
71 | } else headOfList=headOfList->next; |
||
72 | |||
73 | delete [] deleteNode; |
||
74 | return retVal; |
||
75 | } |
||
76 | |||
77 | void |
||
78 | QUEUEint::enQueue(const int& inVal) |
||
79 | { |
||
80 | //Allocate new node |
||
81 | Item *newNode=(Item *) new char[sizeof(Item)]; |
||
82 | |||
83 | //Set value |
||
84 | newNode->data=inVal; |
||
85 | |||
86 | //Set links in newNode |
||
87 | newNode->prev=tailOfList; |
||
88 | newNode->next=NULL; |
||
89 | |||
90 | //Set links to this node |
||
91 | if (tailOfList) { |
||
92 | //Already a tail node whose next pointer we have to fix |
||
93 | tailOfList->next=newNode; |
||
94 | } else { |
||
95 | //first node |
||
96 | headOfList=newNode; |
||
97 | } |
||
98 | tailOfList=newNode; |
||
99 | } |