Home > Back-end >  The program run the abnormal? Why? Small white one, please advise
The program run the abnormal? Why? Small white one, please advise

Time:10-18

# include
# include

Struct list
{
int number;
Struct list * next;
Previous struct list *;
} the head, * node;

Void main ()
{
int i;
Head. Next=NULL;
Head. Previous=NULL;
The node=& amp; The head;
for(i=1; i<=10; I++)
{
Node - & gt; Next=(struct list *) malloc (sizeof (struct list));
Node - & gt; Next - & gt; Previous=node;
The node=node - & gt; Next;
Node - & gt; Number=I;
Node - & gt; Next=NULL;
}

The node=head. The next;//print
Do
{
Printf (" % d ", node - & gt; Number);
The node=node - & gt; Next;
} while (node);
The node=node - & gt; Previous;
Do
{
Printf (" % d ", node - & gt; Number);
The node=node - & gt; Previous;
} while (node - & gt; Previous);
}

CodePudding user response:

Do
{
Printf (" % d ", node - & gt; Number);
The node=node - & gt; Next;
} while (node);
The node=node - & gt; Previous;//the right value of the node==NULL

CodePudding user response:

reference 1st floor sololie response:
do
{
Printf (" % d ", node - & gt; Number);
The node=node - & gt; Next;
} while (node);
The node=node - & gt; Previous;//the right value of the node==NULL

I think in the first line output 1... 10, the second line of the output 10... 1, how to change?
  • Related