-
Notifications
You must be signed in to change notification settings - Fork 5
/
stack.h
83 lines (69 loc) · 1.63 KB
/
stack.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
/*
This is stack.h
Coxeter version 3.0 Copyright (C) 2002 Fokko du Cloux
See file main.cpp for full copyright notice
*/
#ifndef STACK_H /* guard against multiple inclusions */
#define STACK_H
#include "globals.h"
#include "list.h"
namespace stack {
using namespace coxeter;
using namespace list;
/* class declarations */
template <class T> class Fifo;
template <class T> class Stack;
/******* class definitions *************************************************/
template <class T>
class Fifo {
private:
List<T> d_list;
Ulong d_first;
Ulong d_last;
Ulong d_size;
public:
/* constructors and destructors */
void operator delete(void* ptr)
{return arena().free(ptr,sizeof(Fifo));}
Fifo();
~Fifo() {};
/* modifiers */
const T& pop();
void push(const T&);
/* accessors */
Ulong size() const;
const T& top() const;
};
template <class T>
class Stack {
private:
List<T> d_list;
public:
/* constructors and destructors */
void operator delete(void* ptr)
{return arena().free(ptr,sizeof(Stack));}
Stack<T>();
~Stack<T>();
/* modifiers */
const T* pop();
void push(const T&);
/* accessors */
Ulong size() const;
const T& top() const;
};
/******** Inline implementations ******************************************/
template <class T>
inline Ulong Stack<T>::size() const
{return d_list.size();}
template <class T>
inline const T& Stack<T>::top() const
{return d_list[d_list.size()-1];}
template <class T>
inline Ulong Fifo<T>::size() const
{return d_size;}
template <class T>
inline const T& Fifo<T>::top() const
{return d_list[d_first];}
}
#include "stack.hpp"
#endif