I'm pretty sure the answer is a definite no if it is a pointer to a primitive type, but I have created classes called "network", "path", and "node" and I want them all to be able to refer to each other. These are not primitive types, so I hope I can point to them somehow. I don't know the syntax to do that since it appears to be much different from C++ syntax. I am starting with 17 arrays of integers representing paths from leaf nodes to the root node in an ad hoc wireless system. My goal is to build a tree and represent it graphically. I have 25 nodes total, so I'd like to only create 25 node objects, but still have the network and path classes be able to refer to these nodes when building the tree. There are other classes too, but I hope this is enough to demonstrate the problem. I have set up a C++-style vector of pointers to objects, which Java is rejecting. Since these are not primitive types, I can use pointers in some way, correct? Thanks.
// network.java
package AdHcTree2;
import java.util.Vector;
public class network
{
node* rootNode;
Vector <node> netNodes;
Vector <path> netPaths;
public static void main (String args[])
{
network theNetwork = new network ();
theNetwork.CreatePaths();
theNetwork.DisplayParents ();
}
public network ()
{
netNodes = new Vector ();
netPaths = new Vector ();
}
node GetNode (int nodenum)
{
}
void CreatePaths ()
{
int numPaths = 17;
int theArray[][] =
{
{3, 1},
{9, 7, 2, 1}, // 1 is root, 2 is child of 1,
// 7 is child of 2, 9 is child of 9
{10, 8, 2, 1},
{11, 8, 2, 1},
{13, 12, 8, 2, 1},
{14, 12, 8, 2, 1},
{15, 14, 12, 8, 2, 1},
{16, 14, 12, 8, 2, 1},
{17, 14, 12, 8, 2, 1},
{18, 6, 4, 1},
{19, 6, 4, 1},
{20, 5, 4, 1},
{21, 5, 4, 1},
{22, 21, 5, 4, 1},
{23, 22, 21, 5, 4, 1},
{24, 23, 22, 21, 5, 4, 1},
{25, 23, 22, 21, 5, 4, 1}
};
int arraySize[] = {2, 4, 4, 4, 5, 5, 6, 6, 6, 4, 4, 4, 4, 5, 6, 7, 7};
for (int i = 0; i < numPaths; i++)
{
path aPath = new path(this, arraySize[i], theArray[i]);
netPaths.add(aPath);
}
}
public void AddNodeToNetwork (node aNode)
{
}
public void DisplayParents ()
{
}
}
// node.java
package AdHcTree2;
import java.util.Vector;
public class node
{
network* theNetwork;
int nodeNumber;
node* parent;
Vector <node*> children;
int depth;
int column;
public node ()
{
nodeNumber = -1;
}
public node (node aNode)
{
}
public node (int nodenumber, network* thenetwork)
{
}
public node (int nodenumber, network* thenetwork, node* theParent, int theDepth)
{
}
public void AddChild (node* child)
{
}
}
// path.java
package AdHcTree2;
import java.util.Vector;
public class path
{
public Vector <node*> pathNodes;
public path (network aNetwork, int numnodesinpath, int nodenum[])
{
pathNode = new Vector ();
// new nodes are created here with calls to node constructors
}
}