Question: Given a special list, whose node have extra pointer random which point to some other node in linked list. Create another list that is copy
Given a special list, whose node have extra pointer random which point to some other node in linked list. Create another list that is copy of the given list. Also, make sure that random pointer is also allocated to respective node in new list.
Traverse the list and go on adding nodes to the list, which have same value but have random pointer points to null. Now traverse the modified list again. Let us call the node, which was already present in the list as old node and the node, which is added as new node. Find the random pointer node pointed of old node and assign its next node to the random pointer of new node. Follow this procedure for all the nodes. Finally separate the old and new nodes. The list formed by new nodes is the desired list.![//Sorts a given list by selection sort //Input: An array A[ 0..n-1]](https://dsd5zvtm8ll6.cloudfront.net/images/question_images/1708/9/2/6/68065dc26d85490c1708926679065.jpg)
//Sorts a given list by selection sort //Input: An array A[ 0..n-1] of orderable elements. //Output: List A[0..n-1] sorted in ascending order Algorithm SelectionSort (A[ 0..n-1]) for i to n - 2 do min = i for j =i + 1 to n - 1 do if A[j] A[min] min = j swap A[i] and A[min]
Step by Step Solution
3.39 Rating (149 Votes )
There are 3 Steps involved in it
This task involves creating a deep copy of a linked list that includes random pointers Each node in this structure has three components a value a pointer to the next consecutive node and an additional ... View full answer
Get step-by-step solutions from verified subject matter experts
