-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatatype.hpp
189 lines (175 loc) · 4.62 KB
/
datatype.hpp
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
#pragma once
#include <iostream>
#include <string>
using namespace std;
// Creates various data types used to Implement AVL trees for our Dataset
// Course_Data stores all the data of one Course
// Course is a node which contains data and next pointer
// AVL trees are used to store Courses
// Stack is used to balance avl trees
class Course_data
{
public:
bool isUdemy;
std::string name;
std::string url;
int Category_id; // using h
int difficulty_id; // Beginner, advanced etc
int price;
int subscribers;
int course_id;
int publish_year;
float duration;
bool isPaid;
int counter;
float rating;
string difficulty;
string tags[2];
Course_data()
{
isUdemy = false;
counter = 0;
rating = 0;
subscribers = 0;
price = 0;
}
};
class Course
{
public:
int index;
Course *Heap_Root;
Course_data data;
Course *next;
Course *LeftChild;
Course *RightChild;
void PrintCourseData() //function to print the data of the course
{
std::cout << "Course_ID: " << data.course_id << std::endl;
std::cout << "Course title: " << data.name << std::endl;
std::cout << "Link: " << data.url << std::endl;
std::cout << "Difficulty level : " << data.difficulty << std::endl;
cout << "Rating : " << data.rating << endl;
if (data.isUdemy)
{
std::cout << "Category ID: " << data.Category_id << std::endl;
std::cout << "Category: " << data.tags[0] << std::endl;
std::cout << "Price: " << data.price << std::endl;
std::cout << "Number of students enrolled: " << data.subscribers << std::endl;
std::cout << "Year published: " << data.publish_year << std::endl;
std::cout << "Hours to complete: " << data.duration << std::endl;
}
else
{
cout << "Category: " << data.tags[0] << endl;
cout << "Sub-category: " << data.tags[1] << endl ;
}
cout << endl;
}
void InsertUserCourseData() //function to insert the data into the course
{
cout << "Enter course name: " ;
std::cin >> data.name;
cout << "Attach course link: ";
std::cin >> data.url;
cout << "Give category id: ";
std::cin >> data.Category_id;
cout << "Give course price: ";
std::cin >> data.price;
cout << "Give number of subscribers: ";
std::cin >> data.subscribers;
cout << "Year of release = ";
std::cin >> data.publish_year;
cout << "Hours to complete = ";
std::cin >> data.duration;
if (data.price != 0)
data.isPaid == false;
}
};
class LinkedList
{
public:
Course *first;
Course *last;
int length;
Course *ploc;
Course *loc;
LinkedList();
bool isEmpty();
void printList(int, int);
void SearchList(string); //searches through list linearly
void insertFront();
void insertFront(Course *);
void insertNewNode(Course *);
void insert(Course *);
void deleteNode(std::string);
void destroy(); //basic linked list functionalities
};
class stackNode // node to implement Stack datastructure
{
public:
Course *ptr;
stackNode *next;
stackNode()
{
ptr = NULL;
next = NULL;
}
};
class stack
{
public:
int len = 0;
stackNode *start;
stackNode *loc;
stack()
{
start = NULL;
loc = NULL;
}
bool isEmpty();
Course *pop();
void push(Course *);
};
class AVL_Tree
{
public:
stack s; // Used to ballance AVL
Course *root;
Course *loc;
Course *ploc;
int len;
AVL_Tree()
{
len = 0;
root = NULL;
loc = NULL;
ploc = NULL;
}
~AVL_Tree();
bool IsEmpty();
void search(Course *);
void Insert(Course *);
void PreOrder(Course *);
void InOrder(Course *);
void PostOrder(Course *);
int height_of_tree(Course *);
void destroyTree(Course *);
void deleteNode(Course *);
// functions to balance AVL tree
void leftRotation(Course *);
void rightRotation(Course *); // Rotation functions
void leftRightRotaion(Course *);
void rightLeftRotaion(Course *);
int depth_of_tree(Course *); // Returns depth of a node. used for balancing an AVL tree
void ballanceAVL(Course *, int);
// File reading functions
int indexSubject(string);
int stringToint(string);
float stringToFloat(string);
int indexLevel(string);
void insertUdemyDataset();
void insertCourseraDataset();
// Searching functions for strings
void searchCourse(string);
};