Here's a requirements question:
You say values can be either strings or numbers, and that operations (*, +, - ...) can be performed on them.
Can a value change type? Making things immutable when you can is always a good idea...
Are the types required to be the same for an operation to be performed? If not what is the definition of the operation with mixed types?
Are all the types in the data structure the same? If so you can make a much simpler data structure and use Generics to differentiate type.
Main Topics
Browse All Topics





by: rpnmanPosted on 2009-11-08 at 06:40:57ID: 25770602
I'm puzzled to hear you ask "what kind of data structure" you should use. It sounds to me like what you're describing IS a data structure. I think it is far too specialized to find a particular implementation pre-made.
ture behavior. Make a class that can store the value, and can return information about its type, etc. (I'll call this a "Value" object.) Then make a separate class that holds one of these values and manages the linkages for the grid node behavior, and yet a third class that manages the entire structure. That helps keep responsibilities clear and avoids a lot of bugs.
For starters, I suggest encapsulating the value-type behavior separately from the position-in-the-data-struc
What you have described is a net of nodes in the configuration of a torus. This implies the sizes of columns and rows must be fixed, although they can differ. The chief difficulty in such a structure is how to 'grow' it.
If your "Grid" size is fixed after construction you could pass the constructor a rectangular array of values ( Value [ ] [ ] ) and have it stitch right to left and top to bottom internally. If you can impose this restriction on your design, everything becomes easier.
If you need the torus to be be expandable or contractable, you can only do it entire 'row' or 'column' rings at a time. This implies that either the ring is passed in intact or as a liner array of values ( Value [ ] ) of the appropriate size.
The core of your data structure is specialized object you will create to represent the nodes of the grid, with node pointers to its neighbors. Since you have a no requirement for bidirectional traversal of the rings (???) it should be an easy matter to give these a method insertRight(Node) or insertUp(Node) which allow another Node to be added to the ring. I would suggest making this class a private inner class of the Grid/Torus data structure class - no body else should be manipulating it.