-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautomat.cpp
More file actions
85 lines (70 loc) · 2.05 KB
/
automat.cpp
File metadata and controls
85 lines (70 loc) · 2.05 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
#include "automat.h"
#include <iostream>
using namespace std;
extern const int MAX_NODES;
Node::Node(const int id){
next = new vector<string>[MAX_NODES];
identifier = id;
cout << "Created new node at " << next << "\n";
}
Node::Node(){
cout << "Created node array item\n";
next = new vector<string>[MAX_NODES];
}
void Node::setInit(const int id){
///next = new vector<string>[MAX_NODES];
identifier = id;
//cout << "Set new node\n";
}
Node::~Node(){
//cout << "Deleted node\n";
}
void Node::addVertex(const string vertexName, const int to){
//add a vertex between q0 and q1
next[to].push_back(vertexName);
cout << "Created vertex: " << identifier << "->" << to << endl;
return;
}
int Node::getIdentifier()const{return identifier;}
Node& Node::nextNode(const string transition, Node* automat)const{
for(int i = 0; i < MAX_NODES; i++){
for(int j = 0; j < next[i].size(); j++)
{
if(next[i][j] == transition)
return automat[i];
}
}
}
void Node::showVertexes() const{
//debugging for showing all vertexes
for(int i = 0; i < MAX_NODES; i++){
cout << next[i].size() << " ";
}
cout << endl;
}
bool Node::hasVertex(const Node& other) const{
//return whether or not a vertex exists between q0 and q1
if (next[other.identifier].size() != 0) return 1;
else return 0;
}
bool Node::hasVertexNamed(const string s)const{
for(int i = 0; i < MAX_NODES; i++)
for(int j = 0; j < next[i].size(); j++)
if(next[i][j] == s) return true;
return false;
}
Node& Node::operator=(const Node& other){
identifier = other.identifier;
for(int i = 0; i < MAX_NODES; i++)
for(int j = 0; j < next[i].size(); j++)
next[i][j] = other.next[i][j];
cout << "Copied node\n";
return *this;
}
activeNode::activeNode(const int a){
id = a;
}
/*
Node& Node::nextNode(const string letter) const{
*this.hasVertex(letter) ? return
}*/