-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEST.cpp
143 lines (118 loc) · 3.26 KB
/
TEST.cpp
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <iostream>
#include <fstream>
#include <iomanip>
#include <cstdlib>
using namespace std;
///should be copied to .h file
struct Node{
int kadane;
int divCon;
int brute;
Node* next;
Node* prev;
};
class QueueLinkList{
public:
QueueLinkList();
bool isEmpty() const;
const Node& front() const; //return front element
const Node& rear() const; // return back element
int getQueueSize() const; // return number of elements
void add(Node* inputNode,const int& a, const int& b, const int& c);
void enqueue(const int& a, const int& b, const int& c);
void remove(Node* input);
void dequeueFront();
void dequeue();
friend std::ostream& operator<<(std::ostream& out, const QueueLinkList& obj);
~QueueLinkList();
private:
Node* head;
Node* tail;
int queueSize;
};
//should be copied to implementation file .cpp
QueueLinkList::QueueLinkList(){
head = new Node();
tail = new Node();
head ->next = tail;
tail ->prev = head;
queueSize = 0;
}
QueueLinkList::~QueueLinkList(){
while(!isEmpty()) dequeueFront();
delete head;
delete tail;
}
bool QueueLinkList::isEmpty() const{
return (head ->next == tail);
}
const Node& QueueLinkList::front() const{
return *head;
}
const Node& QueueLinkList::rear() const{
return *tail;
}
int QueueLinkList::getQueueSize() const{
return queueSize;
}
void QueueLinkList::add(Node* inputNode,const int& a, const int& b, const int& c){
Node* newNode = new Node();
newNode->brute = a;
newNode->divCon = b;
newNode->kadane = c;
newNode->next = inputNode;
newNode ->prev = inputNode ->prev;
inputNode ->prev -> next = inputNode ->prev = newNode;
}
void QueueLinkList::enqueue(const int& a, const int& b, const int& c){
add(head->next,a, b,c);
queueSize ++;
}
void QueueLinkList::remove(Node* input){
Node* prevNode = input -> prev;
Node* newNode = input ->next;
prevNode ->next = newNode;
newNode ->prev = prevNode;
}
void QueueLinkList::dequeue(){
remove(tail -> prev);
queueSize --;
}
void QueueLinkList::dequeueFront(){
remove(head -> next);
queueSize --;
}
std::ostream& operator<<(std::ostream& out, const QueueLinkList& obj){
Node* temp = obj.tail;
int n =1;
temp = temp->prev;
while( n < obj.getQueueSize()){
temp = temp->prev;
out << temp->brute << ' ' << temp->divCon << ' ' << temp->kadane << std::endl;
n++;
}
return out;
}
int main (void){
QueueLinkList* data= new QueueLinkList();
ifstream input;
input.open("output.txt");
if(!input){
cerr<<"File Not Found"<<endl;
return -1;
}
int inputSize,alg1,alg2,alg3;
string firstLine;
getline(input,firstLine); //skips first line
input>>inputSize>>alg1>>alg2>>alg3;
while(input){
data ->enqueue(alg1,alg2,alg3);
//cout<<alg1<<' '<<alg2<<' '<<alg3<<endl;
input>>inputSize>>alg1>>alg2>>alg3;
}
data->dequeue(); //deletes from da back
cout<< *data <<endl;
cout<<endl;
cout<< data->getQueueSize();
return 0;
}