-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhistory.cpp
More file actions
64 lines (56 loc) · 1.39 KB
/
history.cpp
File metadata and controls
64 lines (56 loc) · 1.39 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
//PANAGIOTIS KONTOEIDIS
//1115201900266
#include "libs.h"
void print_history(history myhistory)
{
if(myhistory.empty()){
cout<<"History is empty"<<endl;
return;
}
for (int i = 0; i < myhistory.size(); i++)
{
cout << i + 1 << ". ";
for (int j = 0; j < myhistory[i].size(); j++)
{
cout << myhistory[i][j] << " ";
}
cout << endl;
}
return;
}
tokens history_command(history myhistory, tokens command)
{
history_flag = 0;
if (command.size() == 1) // if the command is myHistory
{
print_history(myhistory);
history_flag = 1;
return command;
}
int pos = stoi(command[1]); //else get the number of the command in the History
if(pos <= 0 )
{
cout<<"Wrong History Value"<<endl;
exit(-1);
}
if (pos > myhistory.size())
{
cout << "Wrong History Value" << endl;
exit(-1);
}
tokens temp = myhistory[pos - 1]; // search for the command
if (strcmp(temp[0], "myHistory") == 0) // if the command myHistory the recursively find it
{
return history_command(myhistory, temp);
}
else
{
command.clear();
int new_size = temp.size();
for (int i = 0; i < new_size; i++)
{
command.push_back(temp[i]);
}
return command;
}
}