Home > Back-end >  The code data structure
The code data structure

Time:06-05

Please answer a question of data structure:

The following code error reason: the use of an uninitialized local variable head.
But I clearly initialization of

 

# include "HeadLinkList. H"


Int main ()
{
LinkList head;
Init_LinkList (head);

For (int I=0; I & lt; 5; I++)
{
Insert_LinkList_Tail (head, 0);
}

Show_LinkList (head);

return 0;
}

CodePudding user response:

There should be a head=... And your code no.

CodePudding user response:

I've used Init_LinkList initialization will head ah

CodePudding user response:

refer to the second floor Pink_Piggy response:
I've used Init_LinkList initialization will head ah

This function does not modify the value of the head

CodePudding user response:

reference SuperDay reply: 3/f
Quote: refer to the second floor Pink_Piggy response:
I've used Init_LinkList initialization will head ah

The value of this function does not modify the head

Void Init_LinkList (LinkList head)

{

Assert (a head!=NULL);

If (head==NULL) exit (0);



The head - & gt; Next=NULL;

The head - & gt; Data. The num=0;

}

There is nothing wrong with this this this, I think, oh, good difficult

CodePudding user response:

Head is passed to the function, and will not return back, a good reading

CodePudding user response:


Ok, thank you

CodePudding user response:

 if (head==NULL) exit (0); 

Where are the judgment, the head passed or not initialized, compiler hint uninitialized, do you still not initialized

 void Init_LinkList (LinkList * head) 

{

Assert (a head!=NULL);
* head=(LinkList) malloc sizeof (head) (* *);
If (* head==NULL)
The exit (0);



The head (*) - & gt; Next=NULL;

The head (*) - & gt; Data. The num=0;

}

For your reference ~

Call attention to the head before add & amp;;
Namely: Init_LinkList (& amp; The head);

CodePudding user response:

refer to the second floor Pink_Piggy response:
I've used Init_LinkList initialization will head ah

Suggest to see the difference between parameters and arguments, you so fundamentally change the value of the head,

CodePudding user response:

Well well, to pick up address, I thought at that time the meng live,

CodePudding user response:

I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10581430.html
I hope it can help you: https://blog.csdn.net/it_xiangqiang/category_10768339.html
  • Related