-
Notifications
You must be signed in to change notification settings - Fork 0
/
linkedlistjw.h
executable file
·103 lines (88 loc) · 1.88 KB
/
linkedlistjw.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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
#ifndef LINKEDLISTJW
#define LINKEDLISTJW
#include <cstdlib>
#include "basenode_jw.h"
#include <iostream>
//using namespace std;
enum LINKEDLIST_JW_ERROR {LINKEDLIST_JW_EMPTY, LINKEDLIST_JW_FULL, LINKEDLIST_JW_INVALID_MAXSIZE};
class linkedlist_jw{
public:
linkedlist_jw();
virtual ~linkedlist_jw();
bool empty();
bool full();
size_t size();
size_t max_size();
protected:
baseNodeJW *head, *tail;
size_t qty, maxQty;
void insert(baseNodeJW *&whom);
void insertFront(baseNodeJW *&whom);
private:
};
linkedlist_jw::linkedlist_jw()
{
head = new baseNodeJW;
tail = new baseNodeJW;
qty = 0;
maxQty = 50;
}
linkedlist_jw::~linkedlist_jw()
{
qty = 0;
maxQty = 0;
}
bool linkedlist_jw::empty()
{
return !qty;
}
bool linkedlist_jw::full()
{
return !(maxQty - qty);
}
size_t linkedlist_jw::size()
{
return qty;
}
size_t linkedlist_jw::max_size()
{
return maxQty;
}
void linkedlist_jw::insert(baseNodeJW *&whom)
{
//need to fix ....
if(full())
throw LINKEDLIST_JW_FULL;
baseNodeJW *ptr = head;
qty++;
if(!ptr){
head = new baseNodeJW;
tail = new baseNodeJW;
head = whom;
whom->nextNode() = tail;
tail->prevNode() = whom;
}else{
baseNodeJW *ptrToTail = tail->prevNode();
whom->nextNode() = tail;
whom->prevNode() = ptrToTail;
ptrToTail->nextNode() = whom;
tail->prevNode() = whom;
}
}
void linkedlist_jw::insertFront(baseNodeJW *&whom){
baseNodeJW *ptr = head;
//baseNodeJW *ptrToTail = tail;
if(full())
throw LINKEDLIST_JW_FULL;
qty++;
if(!ptr->getValue()){
head = whom;
whom->nextNode() = tail;
tail->prevNode() = whom;
}else{
whom->nextNode() = head;
head->prevNode() = whom;
head = whom;
}
}
#endif // LINKEDLISTJW