-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgraph.cpp
35 lines (31 loc) · 881 Bytes
/
graph.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
//
// Created by Hayden Donofrio on 10/8/20.
//
#include "graph.h"
#include <fstream>
#include <iostream>
Graph::~Graph() {
delete [] adjList;
}
void Graph::generateFile(int vertCount, std::string outputFile = "output.txt") {
LinkedList<int> list;
int counter = vertCount + 1;
LinkedList<int> startingIndexes;
for(int i = 1; i <= vertCount; i ++) {
startingIndexes.push_back(counter);
for (int j = 0; j < adjList[i].size(); j ++) {
list.push_back(adjList[i].get(j));
counter++;
}
}
for (int i = startingIndexes.size() - 1; i >= 0; i --) {
list.push_front(startingIndexes.get(i));
}
list.push_front(vertCount);
std::ofstream outfile;
outfile.open(outputFile);
for (int i = 0; i < list.size(); i++) {
outfile << list.get(i) << std::endl;
}
outfile.close();
}