Home > Back-end >  [for] the C language to realize single header interpolation error appears
[for] the C language to realize single header interpolation error appears

Time:02-07

The result is that


This is my code
 # include & lt; Stdio. H> 
#include

# define OK 1
# define the ERROR 0
# define TRUE 1
# define FALSE 0

Typedef int the Status;
Typedef int ElemType;

//the singly linked list storage structure
Typedef struct LNode
{
ElemType data;
Struct LNode * next;//next to their type struct LNode * pointer
} LNode * LinkList;//LinkList for pointer to structure LNode type

Int ListEmpty LinkList (L)
{
Printf (" \ n is checking... \n");
If (L - & gt; Next) return FALSE.//not empty 0
return TRUE;//short 1
}

/* head interpolation method (forward)
*/
Void CreateList_H (LinkList L, int n)//parameters of the type of LinkList pointer variable (used to point to the new open storage unit), reverse to store values of n elements
{
L=(LinkList) malloc (sizeof (LNode));//open storage space of head node
L - & gt; Next=NULL;//empty lists containing head node
int i;//element quantity count

for(i=0; i{
ElemType e;
LNode * p=(LinkList) malloc (sizeof (LNode));//open up space for new nodes and the pointer to the address
Printf (" please input a list element: ");
The scanf (" % d ", & amp; E);//to the new node data fields input data
P - & gt; Data=https://bbs.csdn.net/topics/e;
Printf (" save complete ~ \ n ");
P - & gt; Next=L - & gt; next;//head node pointer field values (i.e., nodes following new address) is assigned to the new node pointer domain to connect
L - & gt; Next=p;//pointer to pointer domain join order not reverse the new node address assigned to the first node pointer domain to connect
}
}

//list traversal
Void print (LinkList L)
{
LNode * p;
P=L - & gt; next;
If (p==NULL) printf (" list is empty! ");
while(p !=NULL)
{
Printf (" % d ", p - & gt; The data);
P=p - & gt; next;
}
}

Int main ()
{
Int the status;
LinkList L;
CreateList_H (L, 2);
Print (L);
Status=ListEmpty (L);
Printf (" % d \ n ", status);
return 0;
}


thank you

CodePudding user response:

C language pointer to strengthen of the building Lord, it is suggested that see Tan Haoqiang C,
Modified as follows, for reference only:
 # include & lt; Stdio. H> 
#include

# define OK 1
# define the ERROR 0
# define TRUE 1
# define FALSE 0

Typedef int the Status;
Typedef int ElemType;

//the singly linked list storage structure
Typedef struct LNode
{
ElemType data;
Struct LNode * next;//next to their type struct LNode * pointer
} LNode * LinkList;//LinkList for pointer to structure LNode type

Int ListEmpty LinkList (L)
{
Printf (" \ n is checking... \ n ");
If (L - & gt; Next) return FALSE.//not empty 0
return TRUE;//short 1
}

/* head interpolation method (forward)
*/
Void CreateList_H (LinkList * L, int n)//parameters of the type of LinkList pointer variable (used to point to the new open storage unit), reverse to store values of n elements
{
* L=(LinkList) malloc (sizeof (LNode));//open storage space of head node
(* L) - & gt; Next=NULL;//empty lists containing head node
int i;//element quantity count

for(i=0; i{
ElemType e;
LNode * p=(LinkList) malloc (sizeof (LNode));//open up space for new nodes and the pointer to the address
Printf (" please input a list element: ");
The scanf (" % d ", & amp; E);//to the new node data fields input data
P - & gt; Data=https://bbs.csdn.net/topics/e;
Printf (" save complete ~ \ n ");
P - & gt; Next=(* L) - & gt; next;//head node pointer field values (i.e., nodes following new address) is assigned to the new node pointer domain to connect
(* L) - & gt; Next=p;//pointer to pointer domain join order not reverse the new node address assigned to the first node pointer domain to connect
}
}

//list traversal
Void print (LinkList L)
{
LNode * p;
P=L - & gt; next;
If (p==NULL) printf (" list is empty! ");
while(p !=NULL)
{
Printf (" % d ", p - & gt; The data);
P=p - & gt; next;
}
}

Int main ()
{
Int the status;
LinkList L;
CreateList_H (& amp; L, 2);
Print (L);
Status=ListEmpty (L);
Printf (" % d \ n ", status);
return 0;
}

CodePudding user response:

Can you tell me about your thoughts I according to your idea change for you

CodePudding user response:

CreateList_H (L, 2); Here out of the question here passing is to use pointer parameter line CreateList_H (& amp; L, 2);

CodePudding user response:

I'm sorry I didn't see you wrong too much

CodePudding user response:

/* head interpolation method (forward) 
*/
Void CreateList_H (LinkList * PL, int n)//parameters of the type of LinkList pointer variable (used to point to the new open storage unit), reverse to store values of n elements
{
LinkList L=* PL;
L=(LinkList) malloc (sizeof (LNode));//open storage space of head node
* PL=L;
L - & gt; Next=NULL;//empty lists containing head node
int i;//element quantity count

For (I=0; I & lt; n; I++)//cycle input element
{
ElemType e;
LNode * p=(LinkList) malloc (sizeof (LNode));//open up space for new nodes and the pointer to the address
Printf (" please input a list element: ");
The scanf (" % d ", & amp; E);//to the new node data fields input data
P - & gt; Data=https://bbs.csdn.net/topics/e;
Printf (" save complete ~ \ n ");
P - & gt; Next=L - & gt; next;//head node pointer field values (i.e., nodes following new address) is assigned to the new node pointer domain to connect
L - & gt; Next=p;//pointer to pointer domain join order not reverse the new node address assigned to the first node pointer domain to connect
}
}

CodePudding user response:

If in the sub function allocates memory, should pass the secondary pointer inside,

CodePudding user response:

refer to 7th floor CHXCHXKKK response:
if in sub function allocates memory, is to pass the secondary pointer,


A little entanglements or not understand, why the secondary pointer is passed in

CodePudding user response:

refer to 6th floor github_37127447 response:
/* head interpolation method (forward) 
*/
Void CreateList_H (LinkList * PL, int n)//parameters of the type of LinkList pointer variable (used to point to the new open storage unit), reverse to store values of n elements
{
LinkList L=* PL;
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related