Pasting the code here, so we can laugh at him even if
>>1 removes his shitty code from pastebin.
Also saluting myself in the future necromancy of this thread.
#include <iostream>
#include<fstream>
#include<string>
using namespace std;
struct prev;
int verts = 0; //# of verts in the graph
int edge = 0; //# of edges in the graph
int coun = 0; //use it for various purposes
struct prev{ //called prev because of many changes, vertice
prev() { //initialize everything to 0
name = 0;
incount = 0;
outcount = 0;
// checked = false;
}
int name; //so we may only have 1 copy
int incount; //degree of the vertex
int outcount; //misc bookkeeping
int *nextout; //where node is pointing
int *nextin; //what nodes are pointing to it
// bool checked; //for output
};
void checkin(prev *lead); //sets the incount and puts connecting nodes in nextin
void print(prev *lead); //prints number
void rm(prev ld, prev *lead); //decrements incount by 1
void exist(prev *lead, int temp2); //checks to see if an inode exists
int find(int k, prev *lead); //looks for position of a number and returns
int main() {
int temp, temp2;
bool check = false;
prev *lead;
ifstream infile;
infile.open ("graph.dat");
infile >> verts;
infile >> edge;
lead = new prev[verts];
//problem with input causing repitition
//the temps show the correct numbers
//and i have a bool condition checking if it exists or not
//I don't particularly understand...
while (!infile.eof()) {
infile >> temp; //main vertex
infile >> temp2; //what that vertex points to
lead[coun].nextin = new int[verts]; //init in
lead[coun].nextout = new int[verts]; //init out
for (int i = 0; i < verts; i++) //go through all nodes
{
if (lead[i].name == temp) //if a node exists add out node to list and see if the out node exists
{
lead[i].nextout[lead[i].outcount] = temp2;
lead[i].outcount += 1;
check = true;
exist(lead, temp2);
break; //exit loop because node now exists
}
}
if (check == false) { //if node doesn't exist create it
for (int i = 0; i < verts; i++) {
if (lead[i].name == 0) {
lead[i].name = temp;
lead[i].nextout[lead[i].outcount] = temp2;
lead[i].outcount += 1;
exist(lead, temp2);
break;
}
}
}
if (check == true)
check = false;
coun++;
}
checkin(lead);
print(lead);
infile.close();
return 0;
}
void print(prev *lead) {
cout << "{ ";
for (int i=0; i<edge; i++) {
for (int j = 0; j <verts; j++) {
if (lead[j].incount == i)
cout << lead[j].name;
}
}
cout << " }";
}
void exist(prev *lead, int temp2) {
bool checker = false;
for (int i = 0; i < verts; i++) {
if (temp2 == lead[i].name)
checker = true;
break;
}
if (checker == false) {
for (int i = 0; i < verts; i++) {
if (0 == lead[i].name)
lead[i].name = temp2;
}
}
}
void checkin(prev *lead) {
int temp = 0;
for (int i = 0; i < verts; i++) {
for (int j = 0; j < lead[i].outcount; j++) {
temp = find(lead[i].nextout[i], lead);
lead[temp].nextin[lead[temp].incount] = lead[i].name;
lead[temp].incount += 1;
}
}
}
int find(int k, prev *lead) {
for (int i = 0; i < verts; i++) {
if (k == lead[i].name)
return i;
}
}
void rm(prev ld, prev *lead) {
for (int i = 0; i < verts; i++) {
for (int j = 0; j < lead[i].outcount; j++) {
if (ld.name == lead[i].nextin[j] ) {
lead[i].incount-= 1;
break;
}
}
}
}
Contents of file:
17 # of verts
22 # of edges
4 5 #starting vert and where it points
8 5
8 9
8 12
5 1
12 15
5 2
5 6
5 10
5 13
5 16
9 13
12 10
12 13
6 7
10 3
10 11
10 14
13 14
13 16
11 7
14 17