1 Create a function called reverselist that will take a simp

1) Create a function called reverselist that will take a simple list as a parameter and return the reversed list. (We aren’t using the word reverse, since it is also the name of a built-in function.) 2) Create a function called deleteall that will take an item and a list as parameters, and return the list with that item removed.

Solution

Hi, Please find my function.

Please let me know in case of any issue.

Let assume structure of node is:
   /* Link list node */
   struct node
   {
   int data;
   struct node* next;
   };

a)
   /* Function to reverse the linked list */
   struct node* reverse(struct node* head)
   {
   struct node* prev = NULL;
   struct node* current = head;
   struct node* next;
   while (current != NULL)
   {
   next = current->next;
   current->next = prev;   
   prev = current;
   current = next;
   }

   return prev;
   }

b)
   struct node* deleteNode(struct node *head, int item)
   {

       if(head == NULL)
           return NULL;
          
   // When node to be deleted is head node
   if(head->data == item)
   {
   return head->next;
   }
     
   // When not first node, follow the normal deletion process

   // find the previous node
   struct node *prev = head;
   while(prev->next != NULL && prev->item != item)
   prev = prev->next;
     
   // Check if node really exists in Linked List
   if(prev->next == NULL)
   {
   printf(\"\ Given node is not present in Linked List\");

   }else{
       // Remove node from Linked List
       prev->next = prev->next->next;
   }
  
   return head;
   }

1) Create a function called reverselist that will take a simple list as a parameter and return the reversed list. (We aren’t using the word reverse, since it is
1) Create a function called reverselist that will take a simple list as a parameter and return the reversed list. (We aren’t using the word reverse, since it is

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site