-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathValidatorClass.hpp
More file actions
99 lines (89 loc) · 1.84 KB
/
ValidatorClass.hpp
File metadata and controls
99 lines (89 loc) · 1.84 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
93
94
95
96
97
98
/*Author: Karanbir Singh
This is the h and cpp file for the html code validation class*/
#include <iostream>
#include <string>
#ifndef VALIDATORCLASS_hpp
#define VALIDATORCLASS_hpp
using namespace std;
//Node class that will store our htmltags
class Node {
private:
string tag;
Node *next;
public:
Node() {
next = nullptr;
}
Node(string data, Node *link = nullptr){
tag = data;
next = link;
}
friend class Validator;
};
//Validator class that will use nodes and build a linkedlist of strings
class Validator{
private:
int size;
Node *front, *end;
public:
Validator();
~Validator();
void pushTag(string t);
void popTag();
string topTag();
int stackSize();
bool emptyStack();
void checkElements();
};
Validator::Validator(){
size = 0;
front = nullptr;
end = nullptr;
}
Validator::~Validator(){
for(Node* temp; front != nullptr;){
temp = front;
front = front->next;
delete temp;
temp = nullptr;
}
}
string Validator::topTag(){
return front->tag;
}
int Validator::stackSize(){
return size;
}
bool Validator::emptyStack(){
if( size == 0 )
return true;
else
return false;
}
void Validator::pushTag(string tg){
if(front == nullptr){
front = new Node(tg,nullptr);
size++;
}
else{
Node* curr = new Node(tg);
Node* temp = front;
front = curr;
front->next = temp;
size++;
}
}
void Validator::popTag(){
Node* curr = front;
front = front->next;
size--;
delete curr;
}
void Validator::checkElements(){
Node* temp = front;
while( temp != nullptr){
cout << temp->tag << endl;
temp = temp->next;
}
}
#endif