-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
92 lines (79 loc) · 1.91 KB
/
main.cpp
File metadata and controls
92 lines (79 loc) · 1.91 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
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
#include <iostream>
#include <fstream>
#include "ring_buffer/ring_buffer.hpp"
#include "ring_buffer/ring_buffer.cpp"
#include "queue/queue.hpp"
#include "queue/queue.cpp"
#include "stack/stack.hpp"
#include "stack/stack.cpp"
using namespace std;
void write(string filename,Stack<int> stack);
int main(int argc, char **argv)
{
try
{
ifstream read_stream("./input.txt");
int l_dot;
int r_dot;
if (!read_stream.is_open())
{
throw "error in open file";
}
int size;
read_stream.seekg(0, ios::end);
if (read_stream.tellg() == 0)
{
throw "empty file";
}
read_stream.seekg(0, ios::beg);
read_stream >> size;
read_stream >> l_dot;
read_stream >> r_dot;
int buff_elem;
RingBuffer<int> r(size);
for (int i = 0; i <= size; i++)
{
read_stream >> buff_elem;
r.push(buff_elem);
}
read_stream.close();
Queue<int> queue;
int buff;
for (auto it = r.begin(); it != r.end(); ++it)
{
queue.insert(*it);
}
Stack<int> inside;
Stack<int> outside;
for (auto it = queue.begin(); it != queue.end(); ++it)
{
buff = *it;
if (l_dot<= buff && buff <= r_dot ){
inside.push(buff);
}
else{
outside.push(buff);
}
}
write("output_inside.txt",inside);
write("output_outside.txt",outside);
}
catch (string error)
{
cout << error;
}
catch (exception exception)
{
cout << exception.what();
}
return 0;
}
void write(string filename,Stack<int> stack){
ofstream os;
os.open(filename);
os << stack.size() << endl;
while(!stack.empty()){
os<<stack.pop()<<" ";
}
os.close();
}