Home > Back-end >  Problem solving create double linked list
Problem solving create double linked list

Time:10-15

The code shows no problem
# include & lt; stdio.h>
# include & lt; The malloc. H>
Typedef struct node
{
int data;
Struct node * link, * the prior;
} the NODE;
Void the create (NODE * head)
{
The NODE * p, * q;
int i;
p=head;
int n;
Printf (" input the number: \ n ");
The scanf (" % d ", & amp; N);
Printf (" please input values: \ n ");
for(i=1; i<=n; I++)
{
Q=(*) malloc (sizeof (NODE));
The scanf (" % d \ n ", & amp; Q - & gt; The data);
Q - & gt; The link=NULL;
P - & gt; The link=q;
Q - & gt; The prior=p;
p=q;
}
}

Void showlink (NODE * head)
{
NODE * p;
P=the head - & gt; The link;
while(p!=NULL)
{
Printf (" % 5 d ", p - & gt; The data);
P=p - & gt; The link;
}
}
Void main ()
{
NODE * head1;
Head1=(*) malloc (sizeof (NODE));
Create (head1);
Printf (" the output is: \ n ");
Showlink (head1);
printf("\n");
}
But the runtime must lose one more data to have the results

CodePudding user response:

The scanf (" % d \ n ", & amp; Q - & gt; The data);
Instead of
The scanf (" % d ", & amp; Q - & gt; The data);

CodePudding user response:

The
reference 1/f, 5250 response:
the scanf (" % d \ n ", & amp; Q - & gt; The data);
Instead of
The scanf (" % d ", & amp; Q - & gt; The data);

Thank you thank you thank you
  • Related