|
From: Michal M. <mol...@se...> - 2011-05-09 19:31:04
|
Dne 9.5.2011 17:44, Jordan Burnam napsal(a):
> Node *Head;
> Node *Curr;
> Node *Last;
>
>
>
>
> numstep = 5;
>
>
> for( int i = 1; i <= numstep; i++)
> {
> (*Head).ptr_next_node = NULL;
Here you are using Head but you haven't allocated it anywhere. There
must be Head = new Node; before the for loop.
> if((*Head).ptr_next_node == NULL)
What is this good for? You just set it to NULL on previous line.
> {
>
> Last = Head;
> Curr = Head;
> cout << " The " << i << "step, please enter the text for this setp and
> then press enter: ";
> cin >> (*Head).steppy.Instruction;
> (*Head).steppy.stepNum = i;
> (*Head)ptr_next_node = new Node;
Probably missing . here. Note that (*x).y is the same as x->y in this case.
> Curr = (*Head).ptr_next_node;
>
> }
Here you probably intended "else". However it won't work because the if
condition will always be true as explained above.
> cout << "The " << i << " step, please enter the text for this step and
> then press enter: ";
> cin >> (*Curr).steppy.Instruction;
> (*Curr).steppy.stepNum = i;
> (*Curr).ptr_next_node = new Node;
> Last = Curr;
> Curr = (*Curr).ptr_next_node;
===================================
Node *Head;
Node *Curr;
numstep = 5;
Curr = Head = new Node;
Head->ptr_next_node = NULL;
for( int i = 1; i <= numstep; i++)
{
cout << " The " << i
<< "step, please enter the text for this setp and then press enter: ";
cin >> Curr->steppy.Instruction;
Curr->steppy.stepNum = i;
Curr->ptr_next_node = i == numstep ? NULL : new Node;
Curr = Curr->ptr_next_node;
}
Curr = Head;
while(Curr) {
cout << Curr->steppy.stepNum << " " << Curr->steppy.Instruction << endl;
Curr = Curr->ptr_next_node;
}
|