#include
#include
Typedef char DataType.
Typedef struct LinkList
{
DataType data;
Struct LinkList * next;
} LinkList;//define node
Void InsertDataByTail (LinkList * head)//stern interpolation
{
Char x;
LinkList * node;
LinkList * remove;
While (NULL!=the head - & gt; Next)
{
The head=head - & gt; next;
}
Remove=head;
Printf (" input the data (0 stop) : \ n ");
X=getchar ();
While (x!='0')
{
The node=(LinkList *) malloc (sizeof (LinkList));
Node - & gt; Data=https://bbs.csdn.net/topics/x;
Node - & gt; Next=remove - & gt; next;
Remove - & gt; Next=node;
Remove=node;
X=getchar ();
}
}
Void ShowListInfor (LinkList * head)
{
The head=head - & gt; next;
Printf (" output list \ n ");
While (NULL!=head)
{
Putchar (head - & gt; The data);
The head=head - & gt; next;
}
}
Void GetListLength (LinkList * head)
{
int count=0;
While (the head - & gt; Next) {
The head=head - & gt; next;
count++;
}
Printf (" the length is % d \ n ", the count/2);
}
Void main ()
{
LinkList * head;
Head=(LinkList *) malloc (sizeof (LinkList));
The head - & gt; Next=NULL;
InsertDataByTail (head);
ShowListInfor (head);
GetListLength (head);
}
Please input: a b c d e
The chain length of the table is twice the length of the right, let me have to count in GetListLength function/2,
Overall is want to create a head node, tail plug was used to establish a linked list, insert the data and create a linked list,
Why is two times, really don't understand why the count
CodePudding user response:
Because of you this kind of writing is doubleA is a node, then press enter is a node, b is a point, enter another node
X=getchar () is first to get to the character, acquisition of a second return ah, so on
CodePudding user response:
Fun