Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

New Part II Assignment: 1) In the module entry point, create a linked list conta

ID: 3673854 • Letter: N

Question

New Part II Assignment: 1) In the module entry point, create a linked list containing five struct birthday elements (respectively for the following people, from head to tail: Alice, Bob, Mallory, Nancy and Kate). Traverse the linked list and output its contents to the kernel log buffer. Invoke the dmesg command to ensure the list is properly constructed once the kernel module has been loaded. Please take the screen shots. Alice born on Jan 9, 1999; Bob born on March 8, 1978; Mallory born on Dec, 1958; Nancy born on Jun 9, 2003; Kate born on March 8, 1978; 2) Please sort the five struct birthday elements in the list by this sequence: from head to tail, the people are from old to young. You may need to come up with new functions if you need. Traverse the linked list again and output its contents to the kernel log buffer. Invoke the dmesg command to ensure the list is properly rearranged. Please take the screen shots. 3) In the module exit point, delete the elements from the linked list and return the free memory back to the kernel. Again, invoke the dmesg command to check that the list has been removed once the kernel module has been unloaded. Please take the screen shots.

Explanation / Answer

typedef struct node snode;
snode *newnode, *ptr, *prev, *temp;
snode *first = NULL, *last = NULL;

struct node
{
string Name;
   int dateInteger;
struct node *next;
};

snode* createTheNode(char val[],int dob)
{
newnode = (snode *)malloc(sizeof(snode));
if (newnode == NULL)
{
printf(" Memory was not allocated");
return 0;
}
else
{
newnode->name = val;
newnode->dateInteger = dob;
newnode->next = NULL;
return newnode;
}
}
void insertNew()
{
char val[30];
   int dob;
  

printf(" Enter the name");
scanf("%d", val);
   printf("Enter date in ddmmyyyy format");
   scan("%d",&val1);
newnode = createTheNode(val,dob);
if (first == last && last == NULL)
{
first = last = newnode;
first->next = NULL;
last->next = NULL;
}
else
{
last->next = newnode;
last = newnode;
last->next = NULL;
}
printf(" ----INSERTED----");
}

int main()
{
int ch;
char ans = 'Y';
   printf("Enter your five elements");
   insertNew();
   insertNew();
   insertNew();
   insertNew();
   insertNew();
   printf("Lets sort your list now:");
   snode *head_iterate = first;
   for( ; head_iterate->next != NULL; head_iterate = head_iterate->next)
   {
       for(count = head_iterate->next; count != NULL; count = count->next)
       {
           if(head_iterate->dateInteger > count->dateInteger)
           {
               int temp = head_iterate->dateInteger;
               head_iterate->dateInteger = count->dateInteger;
               count->dateInteger = temp;
           }
       }
   }
   nw = first->next;
   printf(" After sorting the Linked list is as follows: ");
   while (nw)
   {
       printf("%d ", nw->dateInteger);
       nw = nw->next;
   }
}