Home > Back-end >  Small white question - why need to head in ShowListData function=head -> next, which step that he
Small white question - why need to head in ShowListData function=head -> next, which step that he

Time:10-02

#include
#include
#include

Typedef int DataType.

Typedef struct LinkList {
DataType data;
Struct LinkList * next;
} LinkList;

Void InsertDataByTail (LinkList * head) {
DataType x;
LinkList * remove;
LinkList * node;
While (NULL!=the head - & gt; Next)
The head=head - & gt; Next;
Remove=head;
Printf (" input the data (1) stop \ n ");
The scanf (" % d ", & amp; X);
While (x!=1)
{
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;
The scanf (" % d ", & amp; X);
}
}

Void ShowListData (LinkList * head)
{
The head=head - & gt; Next;
Printf (" output list \ n ");
While (NULL!=head)
{
Printf (" % d ", the head - & gt; The data);
The head=head - & gt; Next;
}
printf("\n");
}

CodePudding user response:

Are you sure you have to move the cursor to traverse the entire each node in the list.
When the cursor moves to the last element, print pointer move back again, after the last node of the subsequent is NULL

CodePudding user response:

reference 1/f, one sunny side sleep summer has deep response: ,
you'd have to move the cursor to traverse the entire
each node in the list!When the cursor moves to the last element, print pointer move back again, after the last node of the subsequent is NULL

I want to ask the sentence outside loop

CodePudding user response:

reference mountain division 19 any computer on the second floor response:
Quote: 1/f, quoted one sunny side sleep summer already deep response: ,
you'd have to move the cursor to traverse the entire
each node in the list!When the cursor moves to the last element, print pointer move back again, after the last node of the subsequent is NULL

I want to ask outside loop that


Because this list is a head node, the node is not stored data, so have to move the pointer to the first node and then print

CodePudding user response:

reference 3 floor one sunny side sleep summer has deep response:
Quote: refer to the second floor mountain division 19 any computer response:

Quote: 1/f, quoted one sunny side sleep summer already deep response: ,
you'd have to move the cursor to traverse the entire
each node in the list!When the cursor moves to the last element, print pointer move back again, after the last node of the subsequent is NULL

I want to ask outside loop that


Because this list is a head node, the node is not stored data, so have to move the pointer to the first node print

Ok thank you

CodePudding user response:

reference 3 floor one sunny side sleep summer has deep response:
Quote: refer to the second floor mountain division 19 any computer response:

Quote: 1/f, quoted one sunny side sleep summer already deep response: ,
you'd have to move the cursor to traverse the entire
each node in the list!When the cursor moves to the last element, print pointer move back again, after the last node of the subsequent is NULL

I want to ask outside loop that


Because this list is a head node, the node is not stored data, so have to move the pointer to the first node print

Ok thank you
  • Related