the above code is a linked list. it doesn't do the add tail.can any one let me know why? BUT it compiles error-free.Code:#include <stdio.h>
struct node{
int age;
struct node *next;
};
void add_head(struct node **head,struct node *new_node);
void printList(struct node **head);
void add_tail(struct node **head,struct node *new_node);
int main(void){
struct node *head=0;
struct node *newNode;
struct node *newNodeA;
/*create a new Node.Add it to the head*/
newNode=(struct node*)malloc(sizeof(struct node));
newNode->age=2;
add_head(&head,newNode);
printList(&head);
/*create a new Node.Add it to the tail*/
newNodeA=(struct node*)malloc(sizeof(struct node));
newNodeA->age=3;
add_tail(&head,newNodeA);
printList(&head);
}
void add_head(struct node **head,struct node *new_node){
new_node->next=*head;
*head=new_node;
}
void add_tail(struct node **head,struct node *new_node){
struct node *current=*head;
while(current!=NULL){
current=current->next;
}
current->next=new_node;
}
void printList(struct node **head){
struct node *current=*head;
while(current!=NULL){
printf("\n%d",current->age);
current=current->next;
}
}