-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathstack.cpp
More file actions
64 lines (56 loc) · 1.25 KB
/
Copy pathstack.cpp
File metadata and controls
64 lines (56 loc) · 1.25 KB
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
#include "stack.h"
#include <cstdlib>
#include <iostream>
template <class Type>
Stack<Type>::Stack()
{
m_list = new StackItem<Type>();
m_list->m_next = NULL;
}
template <class Type>
void Stack<Type>::push(const Type& tvalue)
{
StackItem<Type>* mm_ptr = m_list->m_next;
StackItem<Type>* mm_item = new StackItem<Type>();
mm_item->m_data = tvalue;
mm_item->m_min = tvalue;
mm_item->m_max = tvalue;
if(mm_ptr != NULL)
{
mm_item->m_max = mm_ptr->m_max;
mm_item->m_min = mm_ptr->m_min;
if(tvalue > mm_ptr->m_max)
mm_item->m_max = tvalue;
if(tvalue < mm_ptr->m_min)
mm_item->m_min = tvalue;
}
mm_item->m_next = mm_ptr;
m_list->m_next = mm_item;
}
template <class Type>
Type Stack<Type>::pop()
{
Type mm_data;
StackItem<Type> *mm_ptr = m_list->m_next;
if(mm_ptr != NULL)
{
mm_data = mm_ptr->m_data;
m_list = mm_ptr;
delete mm_ptr;
}
return mm_data;
}
template<class Type>
Type Stack<Type>::minimum()
{
if(m_list->m_next != NULL)
return m_list->m_next->m_min;
return NULL;
}
template<class Type>
Type Stack<Type>::maximum()
{
if(m_list->m_next != NULL)
return m_list->m_next->m_max;
return NULL;
}