-2
node *add_node(node *front, int year, int month) {
// TODO: Implement add_node
node *new_node = malloc(sizeof(node));
if (new_node==NULL) return NULL; // if new_node is null, then malloc fails, return 
NULL;
// assign given value to new_node
new_node->year = year;
new_node->month=month;


if(front==NULL)  // check if the fron is null, insert the new_node at front.
{
  front = new_node;
  front->next = NULL;
  return front;
}

node *iterator = front;
while (iterator->next!=NULL)       // find the tail of the chain
{
  iterator=iterator->next;
}

iterator->next = new_node;    // insert at the end of the chain
new_node->next=NULL;

return front;

}

这个函数被这个调用:

add_node(table[bucket],year,month,day,hour,pm25,TEMP,iws);

其中表是:节点**表

在调用 add_node(table[bucket]) 之后,我检查了 table[bucket] 并且它仍然为空?这是为什么?

4

0 回答 0