-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommon_header.hpp
More file actions
87 lines (67 loc) · 1.99 KB
/
common_header.hpp
File metadata and controls
87 lines (67 loc) · 1.99 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
#include <map>
#include <stack>
#include <vector>
using namespace std;
namespace myspace {
void print_matrix(int *matrix, int M, int N);
// single linked list: class declaration
class SingleLL {
public:
SingleLL *next;
int data;
SingleLL();
SingleLL(int);
void appendToTail(int);
};
// single linked list node delete given data value: function declaration
SingleLL *deleteSingleLLNode(SingleLL *, int);
// single linked list node delete given pointer to the node
SingleLL *deleteSingleLLNode(SingleLL *, SingleLL *);
// generate single linked list given vector of elements
SingleLL *generateSingleLL(vector<int> *);
// print elements of linked list
int printSingleLL(SingleLL *);
// filling elements of stack
void fill_stack(stack<int> *, vector<int> *);
/********************** graph related **************************/
// defined in coomon_graphs_trees.cpp
class GraphNode {
public:
vector<GraphNode *> adj;
string name;
int data;
bool visited; // used by dfs and bfs
int id; // used by dfs and bfs
GraphNode *parent; // used by dfs and bfs
GraphNode();
GraphNode(int id);
GraphNode(string name);
};
class Graph {
public:
map<int, GraphNode *> map_nodes;
void print_graph();
void clear_graph();
void reset_visited_flags();
};
void createGraph_manual(
Graph &,
vector<vector<int>> &); // need to change the data manually every time
bool depthSearch(GraphNode *, int, SingleLL *&);
bool breadthSearch(GraphNode *, int, SingleLL *&);
/************************************************************************/
class BinTreeNode {
public:
BinTreeNode *left;
BinTreeNode *right;
int data;
int level;
BinTreeNode *parent;
BinTreeNode() : left(NULL), right(NULL), data(0), level(-1), parent(NULL) {}
BinTreeNode(int d)
: left(NULL), right(NULL), data(d), level(-1), parent(NULL) {}
};
enum TreeTraverseMode { INORDER, PREORDER, POSTORDER };
void print_binary_tree(BinTreeNode *, TreeTraverseMode);
// void buildBST();
} // namespace myspace