Home > Back-end >  Structure, list the output is not correct
Structure, list the output is not correct

Time:12-23

As shown in figure, why didn't the first line, but not output to the 0 0???????

CodePudding user response:

Traverse the list to them with the do... While
?Tend to be like this:
 
While (p - & gt; Next!=NULL)
{
Printf (" % d, % f ", p - & gt; Num, p - & gt; Pay);
P=p - & gt; Next;
}

CodePudding user response:

Stick a source ~ ~ don't recommend posted pictures

CodePudding user response:

reference 1st floor CHXCHXKKK response:
traverse the list for them with the do... While
?Tend to be like this:
 
While (p - & gt; Next!=NULL)
{
Printf (" % d, % f ", p - & gt; Num, p - & gt; Pay);
P=p - & gt; Next;
}

What is the problem? Like you to change the wrong, also directly without the first worker's salary,

CodePudding user response:

reference 2 building self-confidence boy reply:
post picture source ~ don't recommend ~

Good????

CodePudding user response:

The
refer to the original poster AruNi °? Response:
as shown in figure, why didn't the first line, but not output to the 0 0???????


#include
#include
Struct the Employee
{
int num;
Float pay;
Struct the Employee * next;
};
Struct the Employee * creat ()
{
Head, struct the Employee * * p1, * (p2);
int n=0;
P1=p2=(struct the Employee *) malloc (sizeof (struct Employee));
The head=NULL;
The scanf (" % d, % f ", & amp; P1 - & gt; Num, & amp; The p2 - & gt; Pay);
While (p1 - & gt; Num!=0)
{
N=n + 1;
If (n==1)
The head=p1;
The else
The p2 - & gt; Next=p;
P1 p2=;
P1=(struct the Employee *) malloc (sizeof (struct Employee));
The scanf (" % d, % f ", & amp; P1 - & gt; Num, & amp; The p2 - & gt; Pay);
}
The p2 - & gt; Next=NULL;
Return (the head);//returns the first node in the linked list to the starting address
}
Void list (struct the Employee * head)
{
Struct the Employee * p;
p=head;
Printf (" The linked list: \ n ");
If (a head!=NULL)
Do
{
Printf (" % d, % 2 f \ n ", p - & gt; Num, p - & gt; Pay);
P=p - & gt; Next;
} while (p!=NULL);
}
Int main ()
{
Struct the Employee * head;
The head=creat ();
The list (the head);
return 0;
}