# Need help figuring out what data structure to use for this project

Chewy Bucky

Greenhorn

Posts: 1

posted 10 years ago

- 0

/** Adds a node to this graph.

@param node the node to add

@throws IllegalArgumentException if node already exists in the graph

@throws NullPointerException if node is null*/

void addNode(Object node){

}

/** Adds an edge that joins two nodes.

@param fromNode the starting node for this edge

@param toNode the ending node for this edge

@param edge the edge to add

@throws IllegalArgumentException if edge already exists in the graph,

or if startNode or endNode do not exist.

@throws NullPointerException if edge is null

*/

void addEdge(Object fromNode, Object toNode, Object edge){

}

/** Gets the start node of a given edge.

@param edge an edge of this graph

@return the start node of this edge, or null if this edge does not

exist in the graph.

*/

Object getStartNode(Object edge){

}

/** Gets the start node of a given edge.

@param edge an edge of this graph

@return the end node of this edge, or null if this edge does not

exist in the graph.

*/

Object getEndNode(Object edge){

}

/** Gets all nodes in this graph.

@return an immutable collection of all nodes in this graph

*/

Collection getNodes(){

}

/** Gets all edges that start or end with the given node.

@param node a node of this graph

@return an immutable collection of all edges that start or end

with node. The collection should be empty if node is a node of this

graph

*/

Collection getEdges(Object node){

}

}

Stumped on figuring out what data structure to use that's simpliest to implement.

[ October 18, 2005: Message edited by: Chewy Bucky ]

@param node the node to add

@throws IllegalArgumentException if node already exists in the graph

@throws NullPointerException if node is null*/

void addNode(Object node){

}

/** Adds an edge that joins two nodes.

@param fromNode the starting node for this edge

@param toNode the ending node for this edge

@param edge the edge to add

@throws IllegalArgumentException if edge already exists in the graph,

or if startNode or endNode do not exist.

@throws NullPointerException if edge is null

*/

void addEdge(Object fromNode, Object toNode, Object edge){

}

/** Gets the start node of a given edge.

@param edge an edge of this graph

@return the start node of this edge, or null if this edge does not

exist in the graph.

*/

Object getStartNode(Object edge){

}

/** Gets the start node of a given edge.

@param edge an edge of this graph

@return the end node of this edge, or null if this edge does not

exist in the graph.

*/

Object getEndNode(Object edge){

}

/** Gets all nodes in this graph.

@return an immutable collection of all nodes in this graph

*/

Collection getNodes(){

}

/** Gets all edges that start or end with the given node.

@param node a node of this graph

@return an immutable collection of all edges that start or end

with node. The collection should be empty if node is a node of this

graph

*/

Collection getEdges(Object node){

}

}

Stumped on figuring out what data structure to use that's simpliest to implement.

[ October 18, 2005: Message edited by: Chewy Bucky ]

Barry Gaunt

Ranch Hand

Posts: 7729

posted 10 years ago

- 0

Here's some collections from Sun's Tutorial. Just select those that seem useful to you.

Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch

Getting someone to think and try something out is much more useful than just telling them the answer.

John Mikhail

Greenhorn

Posts: 20

Barry Gaunt

Ranch Hand

Posts: 7729

posted 10 years ago

Of course it does. That's why we give hints not the solution (at this stage).

- 0

Originally posted by John Mikhail:

Not to sound cynical, but does this seem like someone asking to have their homework done for them??

Of course it does. That's why we give hints not the solution (at this stage).

Getting someone to think and try something out is much more useful than just telling them the answer.

Layne Lund

Ranch Hand

Posts: 3061

posted 10 years ago

- 0

To help you decide, you should consider what kind of data you need to store. Also, how do you need to retrieve it? Feel free to post your thoughts here and we will be glad to help.

Also note that graphs are a well known data structure. There are at least two common ways of representing a graph. If you use Google, you should find some discussions about this.

Layne

Also note that graphs are a well known data structure. There are at least two common ways of representing a graph. If you use Google, you should find some discussions about this.

Layne

It is sorta covered in the JavaRanch Style Guide. |