dblqueue.hpp
Go to the documentation of this file.
1
/*----------------------------------------------------------------------------*/
2
/* */
3
/* Copyright (c) 1995, 2004 IBM Corporation. All rights reserved. */
4
/* Copyright (c) 2005-2014 Rexx Language Association. All rights reserved. */
5
/* */
6
/* This program and the accompanying materials are made available under */
7
/* the terms of the Common Public License v1.0 which accompanies this */
8
/* distribution. A copy is also available at the following address: */
9
/* https://www.oorexx.org/license.html */
10
/* */
11
/* Redistribution and use in source and binary forms, with or */
12
/* without modification, are permitted provided that the following */
13
/* conditions are met: */
14
/* */
15
/* Redistributions of source code must retain the above copyright */
16
/* notice, this list of conditions and the following disclaimer. */
17
/* Redistributions in binary form must reproduce the above copyright */
18
/* notice, this list of conditions and the following disclaimer in */
19
/* the documentation and/or other materials provided with the distribution. */
20
/* */
21
/* Neither the name of Rexx Language Association nor the names */
22
/* of its contributors may be used to endorse or promote products */
23
/* derived from this software without specific prior written permission. */
24
/* */
25
/* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS */
26
/* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT */
27
/* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS */
28
/* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT */
29
/* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, */
30
/* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED */
31
/* TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, */
32
/* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY */
33
/* OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING */
34
/* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS */
35
/* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
36
/* */
37
/*----------------------------------------------------------------------------*/
38
#ifndef DBLQUEUE
39
#define DBLQUEUE
40
//#define MYDEBUG
41
#include <stdio.h>
42
#include "
regexp.hpp
"
43
44
class
doubleQueue
{
45
public
:
46
doubleQueue
(
int
n);
// create queue with size n
47
~doubleQueue
();
48
void
push
(
int
value);
// push on top
49
void
put
(
int
value);
// insert at bottom
50
int
pop
();
// pop from top
51
// queue is empty when only one SCAN element is in it
52
bool
isEmpty
() {
53
if
(
head
+1 ==
tail
-1 && (
memory
[
tail
-1] ==
SCAN
))
return
true
;
54
else
return
false
;
55
}
56
#ifdef MYDEBUG
57
// show contents of queue
58
void
dump() {
59
printf(
"double queue: {"
);
60
for
(
int
i=
head
+1;i<
tail
;i++) {
61
if
(
memory
[i] ==
SCAN
) printf(
"SCAN"
);
62
else
printf(
"%d"
,
memory
[i]);
63
if
(i <
tail
-1) printf(
", "
);
64
}
65
printf(
"}\n"
);
66
}
67
#endif
68
69
private
:
70
void
enlarge
();
// make int array bigger if needed
71
72
int
*
memory
;
// array holding elements of queue
73
int
size
;
// size of array
74
int
head
;
// position of head of queue
75
int
tail
;
// position of tail of queue
76
};
77
78
#endif
doubleQueue
Definition:
dblqueue.hpp:44
doubleQueue::~doubleQueue
~doubleQueue()
Definition:
dblqueue.cpp:52
doubleQueue::doubleQueue
doubleQueue(int n)
Definition:
dblqueue.cpp:45
doubleQueue::put
void put(int value)
Definition:
dblqueue.cpp:74
doubleQueue::isEmpty
bool isEmpty()
Definition:
dblqueue.hpp:52
doubleQueue::size
int size
Definition:
dblqueue.hpp:73
doubleQueue::pop
int pop()
Definition:
dblqueue.cpp:87
doubleQueue::tail
int tail
Definition:
dblqueue.hpp:75
doubleQueue::memory
int * memory
Definition:
dblqueue.hpp:72
doubleQueue::head
int head
Definition:
dblqueue.hpp:74
doubleQueue::enlarge
void enlarge()
Definition:
dblqueue.cpp:106
doubleQueue::push
void push(int value)
Definition:
dblqueue.cpp:62
regexp.hpp
SCAN
#define SCAN
Definition:
regexp.hpp:44
oorexx
executor
sandbox
jlf
trunk
extensions
rxregexp
dblqueue.hpp
Generated by
1.9.2