A Building is a series of floors
A Floor is a series of rooms
A Room is a series of walls
A Wall is a rectangular space followed by none or more WinDoors
A Windoor (“window or doorway”) is a rectangular space
A door may contain a window
A window will contain one or more panes of glass
A TYPE structure to define a rectangular shape is:-
Type typWinDoor
sngLeft As Single
sngUp As Single
sngHeight As Single
sngWidth As Single
sngTop As Single
End Type
A door, as an example, is said to start 12 inches from the left edge of the wall and begins 0 inches up from the floor. The door is 30 inches wide and 77 inches high.
The wall above has a two-pane window, and a door with a two-pane window.
The wall above has a window with two vertical sections, each vertical section contains two sections. Each lower section contains two small panes. (Or if you prefer, two horizontal sections with the lower section divided into four panes.
The typWinDoor contains the data required to print any rectangle, be it a floor, a wall, a Windoor, a pane, even a cat-flap.
The problem: I would like a pane to belong to a window, which belongs to a door, which belongs to a wall, which belongs to a floor, which belongs to a building.
To that end I augment my typWindoor with an array of sub-rectangles:-
Type typWinDoor
sngLeft As Single
sngUp As Single
sngHeight As Single
sngWidth As Single
sngTop As Single
typW() As typWinDoor
End Type
The array typeW is recursive and this, of course, causes a circular reference compile error in Word2003/VBA.
I cannot recall ever defining a data item with a circular reference. Procedures of program code YES (The Ackerman Function).
Maybe in all my programming I never needed a recursive data structure, but I find that hard to believe. Computer languages allow recursive functions, and so to the compiler such a definition must be a recursive data structure (the program code is data to the compiler).
Question 1: Any suggestions as to how to define a recursive nested data structure are welcomed. In the case of a building/floor/wall etc the depth of recursion will be finite (although VBE does not know that)
Question 2: Anyone who has defined and used a recursive data definition might explain to me why they needed it, and how they programmed it. Possibly with a reference to the implementation language.
Thanks
Chris
Recursive data structure (definition)
-
- PlutoniumLounger
- Posts: 15498
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Recursive data structure (definition)
You do not have the required permissions to view the files attached to this post.
An expensive day out: Wallet and Grimace
-
- PlutoniumLounger
- Posts: 15498
- Joined: 24 Jan 2010, 23:23
- Location: brings.slot.perky
Re: Recursive data structure (definition)
as distinct from recursively defining functions.ChrisGreaves wrote: ↑16 Mar 2021, 14:04...Maybe in all my programming I never needed a recursive data structure, ...
Cheers
Chris
An expensive day out: Wallet and Grimace