Home > Back-end >  The creation of a linked list
The creation of a linked list

Time:09-26

# include & lt; Stdio. H>
# include & lt; The malloc. H>
# include & lt; Stdlib. H>

Typedef struct Node Node;
Typedef struct Node * PNODE;
Struct Node
{
int data;//data domain
Struct Node * pNext;//pointer field
};//the NODE is equivalent to struct NODE PNODE equivalent to the struct NODE *

//function declaration
PNODE create_list (void);//create a list
Void traverse_list (PNODE pHead);//traverse the list
//bool utilities like is_empty that (PNODE pHead);//whether the list is empty
//int length_list (PNODE);//o list length
//bool insert_list (PNODE pHead, int pos, int val);//in the list of the pos pHead points to a node in the front of the insert a new node, the node value is val, and the value of the pos start from 1
//bool delete_list (PNODE pHead, int pos, int * pVal);//delete the first pos a node list, and will remove the value of the node in the pVal points to variable, and the value of the pos start from 1
//void sort_list (PNODE);//the list sorted


Int main (void)
{
PNODE pHead=NULL;//equivalent to the struct Node * pHead=NULL;
//int val.

PHead=create_list (); ://create_list () function creates an acyclic singly linked lists, and will pay the list head node address pHead
Traverse_list (pHead);

//insert_list (pHead, 4, 33);
/* if (delete_list (pHead, 4, & amp; Val))
{
Printf (" deleted successfully, you delete elements is: % d \ n ", val);
}
The else
{
Printf (" delete failed! You remove the element does not exist! \n");
}
*/
Traverse_list (pHead);

//int len=length_list (pHead);
//printf (" the length of the list is % d \ n ", len);

//sort_list (pHead);
//traverse_list (pHead);

/* if (utilities like is_empty that (pHead))
Printf (" list is empty! \n");
The else
Printf (" list is not empty! \n");
*/
system("pause");
return 0;
}

PNODE create_list (void)
{
int len;//used to store the number of effective node
int i;
int val;//used for temporary storage of user input node values

//allocate a valid data is not stored head node
PNODE pHead=(PNODE) malloc (sizeof (NODE));
If (NULL==pHead)
{
Printf (" allocation failure, the program terminates. \n");
The exit (1);
}
PNODE pTail=pHead;
PTail - & gt; PNext=NULL;

Printf (" please enter you need to generate the number of nodes in the list: len=");
The scanf (" % d ", & amp; Len);

for (i=0; i{
Printf (" please enter the first % d node values: ", I + 1);
The scanf (" % d ", & amp; Val);

PNODE pNew=(PNODE) malloc (sizeof (NODE));
If (NULL==pNew)
{
Printf (" allocation failure, the program terminates. \n");
The exit (1);
}
PNew - & gt; Data=https://bbs.csdn.net/topics/val;
PTail - & gt; PNext=pNew;
PNew - & gt; PNext=NULL;
PTail=pNew;
}

Return pHead;
}

Void traverse_list (PNODE pHead)
{
PNODE p=pHead - & gt; PNext;

While (NULL!=p)
{
Printf (" % d ", p - & gt; The data);
P=p - & gt; PNext;
}
printf("\n");

return;
}



1> -- -- -- -- -- - has started to generate: project: text7, configuration: Debug Win32 -- -- -- -- -- --
1> Generate the start time for 2020/4/21 18:15:42,
1> InitializeBuildStatus:
1> Is "the Debug \ text7 unsuccessfulbuild" Touch mission,
1> ClCompile:
1> Text7. C
1> D: \ vs2010test \ text7 \ text7 \ text7 c (71) : error C2275: "PNODE" : this type is used as the expression of illegal
1> D: \ vs2010test \ text7 \ text7 \ text7 c (6) : see "PNODE statement
"1> D: \ vs2010test \ text7 \ text7 \ text7 c (71) : error C2146: syntax errors: lack of ";" (in front of the identifier "pTail")
1> D: \ vs2010test \ text7 \ text7 \ text7 c (71) : error C2065: "pTail" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (71) : warning C4047: "=", "int" and "PNODE" indirect level of different
1> D: \ vs2010test \ text7 \ text7 \ text7 c (72) : error C2065: "pTail" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (72) : error C2223: "- & gt; PNext "on the left must point to structure/joint
1> D: \ vs2010test \ text7 \ text7 \ text7 c (82) : error C2275: "PNODE" : this type is used as the expression of illegal
1> D: \ vs2010test \ text7 \ text7 \ text7 c (6) : see "PNODE statement
"1> D: \ vs2010test \ text7 \ text7 \ text7 c (82) : error C2146: syntax errors: lack of ";" (in front of the identifier "pNew)
1> D: \ vs2010test \ text7 \ text7 \ text7 c (82) : error C2065: "pNew" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (82) : warning C4047: "=", "int" and "PNODE" indirect level of different
1> D: \ vs2010test \ text7 \ text7 \ text7 c (83) : error C2065: "pNew" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (83) : warning C4047: "==" : "void *" and "int" indirect level of different
1> D: \ vs2010test \ text7 \ text7 \ text7 c (88) : error C2065: "pNew" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (88) : error C2223: "- & gt; Data "on the left-hand side of the must point to structure/joint
1> D: \ vs2010test \ text7 \ text7 \ text7 c (89) : error C2065: "pTail" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (89) : error C2223: "- & gt; PNext "on the left must point to structure/joint
1> D: \ vs2010test \ text7 \ text7 \ text7 c (89) : error C2065: "pNew" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (90) : error C2065: "pNew" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (90) : error C2223: "- & gt; PNext "on the left must point to structure/joint
1> D: \ vs2010test \ text7 \ text7 \ text7 c (91) : error C2065: "pTail" : no statement of identifiers
1> D: \ vs2010test \ text7 \ text7 \ text7 c (91) : error C2065: "pNew" : no statement of identifiers
1>
1> Generate failure,
1>
1> Elapsed time 00:00:00. 35
==========: zero success, failure, latest 0, 0 skip==========
Why you can run the code in vc6, appeared in the vs2010 it happens!

CodePudding user response:

Is not the same as the standard,
Typedef struct Node Node;
Typedef struct Node * PNODE;
On the structure behind the statement,

CodePudding user response:

nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related