Consider an ANSI C implementation of a first-in-first-out queue using a singly l
ID: 3824941 • Letter: C
Question
Consider an ANSI C implementation of a first-in-first-out queue using a singly linked list. Two global pointers for the linked list are declared as struct LLnode *head *tail; and initialized as head = newLLnode ("" 0); tail = head; Write an ANSI C structure LLnode for a singly linked list node that contains two data variables, i.e. name (a null terminated string) and id (an integer). Write an ANSI C function newLLnode to dynamically allocate and initialize a new LLnode. The function takes in initial values of name and id as inputs and returns a pointer to the new LLnode. Write an ANSI C function addLLnode to append an LLnode to the linked list. The function takes in a pointer to the LLnode and returns nothing. Write an ANSI C function removeLLnode to retrieve and remove an LLnode from the linked list in a first-in-first-out manner. The function takes in nothing and returns the removed LLnode.Explanation / Answer
Q1 struct LLnode
{
string name;
int id;
LLnode next;
}
Q2 LLNode* newLLnode(){
LLnode * newnode = malloc(sizeof(LLnode));
return newnode;
}
Q3 void addNode(LLnode* node){
while(tail.next!=null){
tail = tail.next;
}
tail.next = node;
}
Q4 LLnode removeLLnode(){
LLnode node = head;
head = head.next;
free(node);
}