-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTransition.cpp
More file actions
46 lines (42 loc) · 1.13 KB
/
Transition.cpp
File metadata and controls
46 lines (42 loc) · 1.13 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
#include "Transition.h"
using namespace std;
Transition::Transition(int newState, string popOffOne, string pushOnOne, string popOffTwo, string pushOnTwo) {
this->newState = newState;
this->popOffOne = popOffOne;
this->pushOnOne = pushOnOne;
this->popOffTwo = popOffTwo;
this->pushOnTwo = pushOnTwo;
}
Transition::~Transition() {
}
int Transition::doTransition(stack<char>* stackOne, stack<char>* stackTwo) {
if(popOffOne != "!") {
for(unsigned int i = 0; i < popOffOne.length(); i++) {
if(!stackOne->empty() && popOffOne[i] == stackOne->top()) {
stackOne->pop();
} else {
return -1;
}
}
}
if(pushOnOne != "!") {
for(unsigned int i = 0; i < pushOnOne.length(); i++) {
stackOne->push(pushOnOne[i]);
}
}
if(popOffTwo != "!") {
for(unsigned int i = 0; i < popOffTwo.length(); i++) {
if(!stackTwo->empty() && popOffTwo[i] == stackTwo->top()) {
stackTwo->pop();
} else {
return -1;
}
}
}
if(pushOnTwo != "!") {
for(unsigned int i = 0; i < pushOnTwo.length(); i++) {
stackTwo->push(pushOnTwo[i]);
}
}
return newState;
}