I as having some trouble with linked list. What I am basically trying to do is create a doubly linked list with 10 nodes. Each node represents a frame of bowling. Since I am not adding or removing nodes throughout the program a vector seems like a better choice to me, but its not up to me. First I just want to create a list with ten nodes (frames). This is what I have (pertaining to this issue, I have more):
frame *head; //declarations in class header
frame *back;
---------------------------------------------------
int e=0;
head = new frame;
while (e<9)
{
head->next =new frame;
e++;
}
----------------------------------------------------
player:layer() //constructor in class player
{
head = new frame;
head->score=0;
head->ball1=0;
head->ball2=0;
head->ball3=0;
back = head;
}
----------------------------------------------------
declarations is frame:
class frame
{
public:
int score;
int ball1;
int ball2;
int ball3;
frame *prev;
frame *next;
};
I've tried to cut out a lot of the program and just get to the heart of the matter. All I am really asking is is this a proper way to build a linked list? I am having trouble visualizing the list. My program actually goes through this section, but doesn't assign my constructor values to each frame. Also any suggestions on how to move my pointer along through a list. Still a little shakey on pointers. A generic answer, or one using these examples would be appreciated. Thanks for reading.......