Given a singly linked list, you need to do two tasks. At first reverse the linked list Then, insert a node containing a given valuelelement in the second last index of the linked list. For example, if...


Write the code in python


make it simple to understand please


Given a singly linked list, you need to do two tasks.<br>At first reverse the linked list Then, insert a node containing a given valuelelement in the<br>second last index of the linked list. For example, if the given linked list is 1->2->3->4->5 and<br>value is 19 then the linked list should be modified to 5->4->3->19->2->1. Here, the given linked<br>list was reversed and then a node containing a given value 19 was inserted in the second last<br>index of the linked list<br>If the input linked list is NULL or it has only 1 node then just the current head of the linked list<br>will be returned.<br>

Extracted text: Given a singly linked list, you need to do two tasks. At first reverse the linked list Then, insert a node containing a given valuelelement in the second last index of the linked list. For example, if the given linked list is 1->2->3->4->5 and value is 19 then the linked list should be modified to 5->4->3->19->2->1. Here, the given linked list was reversed and then a node containing a given value 19 was inserted in the second last index of the linked list If the input linked list is NULL or it has only 1 node then just the current head of the linked list will be returned.
Sample 1: Input NULL, 13 output NULL<br>Sample 2: Input 1,20 output 1<br>Sample 3: Input 1->2,33 output 33->2->1<br>Sample 4: Input 1-→2->3,7 output 3->7->2->1<br>Sample 5: Input 1>2->3->4,65 output 4>3->65->2->1<br>Sample 6: Input 1->2->3->4->5>6,21 output 6->5->4->3->21->2>1<br>Input: The function takes two arguments as inputs First one is the reference pointer to the<br>head of the linked list and the second one is an integer which is going to be inserted in the<br>linked list<br>Output: Your function should return the head of the modified linked list If the linked list is<br>empty then it should return NULL<br>User Task: The task is to complete the function revinsert Node head, int elem) which will<br>reverse the linked list and then insert a node containing the given element in the second<br>last index of the linked list.<br>

Extracted text: Sample 1: Input NULL, 13 output NULL Sample 2: Input 1,20 output 1 Sample 3: Input 1->2,33 output 33->2->1 Sample 4: Input 1-→2->3,7 output 3->7->2->1 Sample 5: Input 1>2->3->4,65 output 4>3->65->2->1 Sample 6: Input 1->2->3->4->5>6,21 output 6->5->4->3->21->2>1 Input: The function takes two arguments as inputs First one is the reference pointer to the head of the linked list and the second one is an integer which is going to be inserted in the linked list Output: Your function should return the head of the modified linked list If the linked list is empty then it should return NULL User Task: The task is to complete the function revinsert Node head, int elem) which will reverse the linked list and then insert a node containing the given element in the second last index of the linked list.
Jun 10, 2022
SOLUTION.PDF

Get Answer To This Question

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here