은 내가이 연결리스트에 대해 이해할 수없는 것은
비주얼 스튜디오.
머리와 꼬리가 지정 될 때 node_temp의 메모리 주소는 tail과 head 모두에 대해 동일한 메모리 위치를 가리 킵니다.
그러나 else 부분은 사실 꼬리를 가리키는 머리입니다. 설명 할 수없고 else 부분에 대해 이해할 수없는 것이 있습니다.
나는 나를 위해 더 잘 설명 할 수 있기를 바랍니다. 링크 된 목록에 추가 할 때 머리가 변경되지 않기 때문에
static struct convert_temp
{
size_t cel;
size_t fah;
struct convert_temp *next;
} *head = NULL, *tail = NULL;
/** Add the new converted temperatures on the list */
void add(size_t cel, size_t fah)
{
struct convert_temp *node_temp = NULL; /* contain temp data */
node_temp = malloc(sizeof(*node_temp));
if(node_temp == NULL)
{
fprintf(stderr, "Cannot allocate memory [ %s ] : [ %d ]\n",
__FUNCTION__, __LINE__);
exit(0);
}
/* Assign data */
node_temp->cel = cel;
node_temp->fah = fah;
node_temp->next = NULL;
if(head == NULL)
{
/* The list is at the beginning */
head = node_temp; /* Head is the first node = same node */
tail = node_temp; /* Tail is also the last node = same node */
}
else
{
/* Append to the tail */
tail->next = node_temp;
/* Point the tail at the end */
tail = node_temp;
}
}
디버거를 사용하십시오. –