Linked List Help
I am building a program tell score for a game of bowling. I have created a doubly linked list of ten frames. Each frame includes three integers - ball1, ball2, and ball3 for the 10th frame only.
For my scoring I need to look back one and possibly two frames to calculate the score, depending on strikes and spares previously thrown.
My question is how do I retrieve the values of those balls?
I'll strip it down to just one very basic example, because if I can figure out the syntax I can implement it throughout my program.
head is a pointer
prev is a pointer in frame
total is a local variable of type int
Any help using this example or a generic one would be great. I am still figuring out how to move within linked lists so any suggestions would be helpful. Thanks for the time:)
What you have will only work if your list is circular (which I doubt it is). If you have a pointer to the end of your list, then you go back a frew frames using it. But it sounds like you need to get your understanding of pointers down a bit more.
Review this, it may sharpen the picture a bit.
current->ball //ball from this frame
current->prev->ball //ball from one frame ago
current->prev->prev->ball //ball from two frames ago
make sure there is a ball from previous frames however before you call for them, otherwise you will get a sneaky error in the code.
This will work if a node is defined something like this:
node * prev;//points to previous node, if it exists
node * next;//points to next node, if it exists
Thanks for the help
Appreciate the suggestions, my problem from earlier was that I should have been entering them like this:
instead of calling a function to do this:
Dumb mistake from staring at the screen to long........
trial and error and asking question = the way to learn.......