Created
October 25, 2015 05:11
-
-
Save anonymous/04dd1b132cfe2dbcbcef to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void ReadInArrayRep(int arrayRep[10][3], int& nodeNum); | |
int main() | |
{ | |
int arrayRep[10][3]; | |
int adjMat[10][10]; | |
int nodeNum, i; | |
ReadInArrayRep(arrayRep[][3], nodeNum); | |
/* for(i = 0; i < nodeNum; i++) //read in left, middle, and right child array rep from user | |
{ | |
cin >> arrayRep[i][0] >> arrayRep[i][1] >> arrayRep[i][2]; | |
}*/ | |
for(i = 0; i < nodeNum; i++) | |
{ | |
for(int j = 0; j < nodeNum; j++) | |
{ | |
if(arrayRep[i][0] != -1 && arrayRep[i][0] == j + 1) | |
{ | |
adjMat[i][j] = 1; | |
} | |
else if(arrayRep[i][1] != -1 && arrayRep[i][1] == j + 1) | |
{ | |
adjMat[i][j] = 1; | |
} | |
else if(arrayRep[i][2] != -1 && arrayRep[i][2] == j + 1) | |
{ | |
adjMat[i][j] = 1; | |
} | |
else | |
{ | |
adjMat[i][j] = 0; | |
} | |
} | |
} | |
for(i = 0; i < nodeNum; i++){ | |
for(int j = 0; j < nodeNum; j++) | |
cout << adjMat[i][j] << " "; | |
cout << endl; | |
} | |
return 0; | |
} | |
void ReadInArrayRep(int arrayRep[][3], int& nodeNum) | |
{ | |
cin >> nodeNum; | |
cin.ignore(100, '\n'); | |
for(int i = 0; i < nodeNum; i++) //read in left, middle, and right child array rep from user | |
{ | |
cin >> arrayRep[i][0] >> arrayRep[i][1] >> arrayRep[i][2]; | |
} | |
return; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment