-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.cpp
78 lines (57 loc) · 1.57 KB
/
main.cpp
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
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <sstream>
#include <string>
#include <fstream>
#include "LinkedList.h"
#include "GraphData.h"
using namespace std;
void readList(const char* filepath, LinkedList<GraphData> *theList);
void printEdge(GraphData edge)
{
printf("Edge:%d:%d:%d\n", edge.getVertex1(), edge.getVertex2(), edge.getWeight());
}
int main(void)
{
cout << "Hello world!" << endl;
LinkedList<GraphData> myList;
readList("./tutorial2-graph_info.txt", &myList);
printf("Number elements:%d\n", myList.noElements());
while(!myList.isEmpty())
{
GraphData edge = myList.popFront();
printf("%d %d %d\n", edge.getVertex1(), edge.getVertex2(), edge.getWeight());
}
return 0;
}
void readList(const char* filepath, LinkedList<GraphData> *theList)
{
std::ifstream listFile;
listFile.open(filepath, std::ios::in);
if(listFile.is_open())
{
while( !listFile.eof())
{
std::string line;
std::getline(listFile, line) ;//Get a line of the input file;
if(!listFile.fail())
{
std::stringstream convert(line);
int vertex1;
int vertex2;
int weight;
convert >> vertex1;
convert >> vertex2;
convert >> weight;
GraphData edge(vertex1, vertex2, weight);
theList->pushBack(edge);
}
}
listFile.close();
}
else
{
std::cout << "Failed to open file\n";
}
}