Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Graph representation

 
Oleg Korsakov
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello!
Very needed help....)

I have to represent a graph. It has nodes connected with arrows from the top node towards the lower ones. How can I using java language to model this graph. Which class should be used for the node and how to represent the arrows between nodes also.
Node can have two downward arrows... How to describe this...

Thanks,
Oleg.
 
A Kumar
Ranch Hand
Posts: 980
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Did you mean showing it on a User interface..??

or are you asking how to represent a node in a class structure??
 
Oleg Korsakov
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I mean the class structure... and realisation of the link between nodes - (class structure too)...
Thanks,
Oleg
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In structures like this each node has pointers to other nodes. The "leaf" nodes at the end have empty or null pointers.

For a singly linked list, each node has one pointer to the next node.

For a doubly linked list, each node has one pointer to the next node, and a pointer back to the prior.

For a binary tree, each node has pointers to two children.

It sounds like your tree might have more than two children, so a collection could be in order.

The existance and direction of the arrow is implied ... the Node with the collection is the plain end of the line, the Nodes in the collection have the arrow end.

Does that work for you? Show us what you make!
 
Oleg Korsakov
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My big thanks to Mr. Stan and yes I'll show it here later (in this topic)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic