|
-
September 26th, 2010, 04:51 PM
#14
Re: Call Array Member in function Help
 Originally Posted by M2W
The array of struct in my first post, and the linked-list in my previous post are intended to be a circular structure. That was my issue with the arrays. I needed to find a way to let the function know that it was working on the last element in the array, and then send the function call to the [0] element, and not to the next element (which would be out of bounds).
With the array, the end of the data structure can be determined from the index which is quite trivial. The nested loops shown in post #12 implement the circular behaviour more or less implicitly, despite the fact that the data structure itself is not circular.
Then I tried using a linked-list. And I figured I would make it circular by connecting the last pointer to the head pointer. The problem is, I don't know how to do this connection precisely. I know the next pointer should point to the top, but I don't know how to code that. It seems like I should just add a line or two to my code on the previous post and it will work.
You don't even have to insert a line. Just change this one during the creation of the initial node as shown in your post #13:
to
This means you begin with a kind-of degenerate circle containing a single node and then extend it node by node.
As the terminating condition of your iteration (or maybe recursion, but see below) isn't determined by the contents of your circular data structure at all, as I think I can conclude from your latest post, it isn't even a big pain not having an end marker in the data structure.
Finally, I want the thing to go into an endless loop, calling function_two on the next node, and then on the next one, etc. I kind of have to use recursion because that is the point of the problem assigned. The loop will end since I will put a counter that will go up with each function_two that is called and once it hits a limit it will exit the do-while.
And yet again I have to say that this is kind of the opposite of a typical recursion scenario. A termination condition based on a counter or even an external event makes this an almost certain candidate for a stack overflow.
But maybe this is kind of a homework assignment? Just recently, in another thread, I have seen a discussion about the fact that they more than merely sometimes are lacking a reasonable point...
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|