-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOthers.cpp
More file actions
66 lines (60 loc) · 1.54 KB
/
Others.cpp
File metadata and controls
66 lines (60 loc) · 1.54 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
#include "Others.h"
char tolow(char ch)
{
if (ch >= 'A' && ch <= 'Z')
return ch - ('Z' - 'z');
return ch;
}
int read(Buffer & buf, HashTable & hashtable, MemoryTable & memorytable)
{
int root = 0;
int temp = 0;
bool first = true;
std::string tok = buf.getNextToken();
if (tok == "(")
{
while ((tok = buf.getNextToken()) != ")")
{
if (first)
temp = root = memorytable.alloc(), first = false;
else
{
memorytable[temp].setRight(memorytable.alloc());
temp = memorytable[temp].getRight();
}
if (tok == "(")
buf.pushBack(), memorytable[temp].setLeft(read(buf, hashtable, memorytable));
else
{
hashtable.hashinsert(tok);
memorytable[temp].setLeft(hashtable.hashfunc(tok));
}
memorytable[temp].setRight(0);
}
return root;
}
else if (tok == std::string())
return root;
hashtable.hashinsert(tok);
return hashtable.hashfunc(tok);
}
void run(HashTable & hashtable, MemoryTable & memorytable, Buffer & buf)
{
memorytable.initmemorytable(), hashtable.hashinsert("("), hashtable.hashinsert(")");
hashtable[0].setSymbol("NIL");
while (true)
{
std::cout << "> ";
std::string input;
std::getline(std::cin, input);
buf.init(input);
memorytable.setNode_root(read(buf, hashtable, memorytable));
std::cout << "] " << "Free list's root = " << memorytable.getFree_list() << std::endl;
std::cout << " " << "List's root = " << memorytable.getNode_root() << std::endl;
memorytable.printTable();
std::cout << std::endl;
hashtable.printTable();
memorytable.print();
memorytable.dealloc();
}
}