-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGraph.cpp
More file actions
68 lines (66 loc) · 1.42 KB
/
Graph.cpp
File metadata and controls
68 lines (66 loc) · 1.42 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
//
// Graph.cpp
// ListMiner
//
// Created by Chenhao Liu on 11/29/12.
// Copyright (c) 2012 Chenhao Liu. All rights reserved.
//
#include "Graph.h"
Graph::Graph(){
graph=new vector<int>();
graph->clear();
}
Graph::Graph(vector<int>* g){
graph=new vector<int>(*g);
}
Graph::Graph(const Graph& g){
graph=new vector<int>(*(g.getter()));
}
vector<int>* Graph::getter() const{
return graph;
};
void Graph::setter(vector<int>* g){
graph=new vector<int>(*g);
}
bool Graph::operator==(const Graph& g) const{
if (g.getter()->size()!=graph->size()) {
return false;
}
int probe=0;
while (probe<graph->size()) {
if (graph->at(probe)!=g.getter()->at(probe)) {
return false;
}
++probe;
}
return true;
}
void Graph::operator=(const Graph& g){
if (graph) {
delete graph;
}
graph=new vector<int>(*(g.getter()));
}
bool Graph::isPartOf(Graph g){
if (graph->size()>g.getter()->size()) {
return false;
}
vector<int>::iterator it1=graph->begin();
vector<int>::iterator it2=g.getter()->begin();
while (it1!=graph->end()&&it2!=g.getter()->end()) {
if ((*it1)==(*it2)) {
++it1,++it2;
} else if(*it1>*it2)
++it2;
else return false;
}
if (it1!=graph->end()) {
return false;
}
return true;
}
Graph::~Graph(){
if (graph) {
delete graph;
}
}