Skip to content

Instantly share code, notes, and snippets.

Created October 25, 2015 05:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save anonymous/04dd1b132cfe2dbcbcef to your computer and use it in GitHub Desktop.
Save anonymous/04dd1b132cfe2dbcbcef to your computer and use it in GitHub Desktop.
#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