This is the best and the simplest explaination and approach of this problem. Really find this wonderful video after searching and didn't regreted a setting, Very nice Explaination Thankyou very much.
write a code to partition a linked list around a value x such that all nodes less than x come before all nodes greater than or equal to x. if x is contained within the list , the values of x only need to be after the elements less than x. the partition element x can appear anywhere in the right partition it does not need to appear between the left and right partitions. input:. 3->5->8->5->10->2->1(partition 5) output: 3->1->2->10->5->5->8
This can be written quite easily if we know how to write a queue but here we dont care about allocating memory Dequeue element from the original linked list Compare key values of dequeued node and pivot node Enqueue dequeued node to the correct sublist Repeat these steps until original list is not empty Lastly sublists can be concatenated If order of nodes with keys equal to pivot key does matter use three sublists First contains nodes less than pivot Second contains nodes equal to pivot Third contains nodes greater than pivot otherwise two sublists will be enough For queue operations and concatenation each list should have pointers to the head node and tail node
Hi Sir, I used to see your videos .Your videos are very very useful for me . I want a video on Flatten a Sorted multilevel linked list and Sort a linked list of 0s, 1s and 2s .Sir Kindly upload upload these videos.
So using if-else condition we're sorting and merging the two already sorted linked lists and using while loop were printing the newly merged single sorted linked list?Amazing explanation sir.
no using the if statement at the beginning we can set the head of the list then using the while loop we can set the rest of the list starting at the head.
another way of merging 2 linked lists: if p->datadata:insert(list,p->data); else insert(list,q->data); am i correct?please advise..!thanks.i built this program in my way and worked...
I apologize if I am incorrect about this, but I was confused about one particular part of this code. When you save newHead = sorting; is that backwards? Should it not be sorting = newHead?
we are assigning the 'sorting' node address to the newHead variable...so newHead = sorting . See if we do " sorting = newHead" , then at this time newHead is Null so sorting will also become Null. So that is not correct. The current address of "sorting" node is the starting address of our answer linked list , so newHead = sorting. Once we save the address in newHead , now "sorting" variable is free to move further.
Vivekanand Khyade - Algorithm Every Day I see where our code differs. I assigned the lesser of the two nodes in the initial comparison to newHead. Then when I assigned the sorting to the newHead it set newHead back to null. That is why I am incorrect.
Your explanation is really good , But code is lengthy you can use the same concept using recursion. Node sortedMerge(Node a, Node b) { Node temp=null; if(a==null) return b; else if(b==null) return a; if(a.data
I would write sorting pointer as local inside function There is missing function which divides list into two sublists and recursive or iterative sorting function How to make this algorithm to work for doubly linked lists To find a midpoint we can use two pointers slow goes once per iteration , fast goes twice per iteration in doubly linked lists we can iterate pointers from both head and tail When we find the midpoid we break the linked list into two sublists Sorting function is similar to this which works for arrays
Natural version of merge sort do not need recursion You can show it If you complete merge sort algorithm we will be able to use linked list for convex hull
Merge sort can be used for sorting files I found in spanish textbook for Pascal natural merge sort for files but i would like to watch version of merge sort with optimized I/O operation Suppose we have limited memory f.e 64kB
How to modify this function that first occurrence of sorted key value has maximum value of next key value Suppose we have points in polar coordinates , we sort them by angle value and after sorting point with first occurrence of angle value has maximum distance from origin We can apply your next algorithm (removing duplicates from sorted linked list) and we will get most time consuming step of Graham's convex hull