Python Program to Sort an array of 0s, 1s and 2s Given an array A[] consisting 0s, 1s and 2s. The task is to write a function that sorts the given array. The functions should put all 0s first, then all 1s and all 2s in last. Examples: Input : {0, 1, 2, 0, 1, 2, 2, 2, 2, 1} Output : {0, 0, 1, 1, 1, 2, 2, 2, 2, 2} Input : {0, 1, 1, 0, 1, 2, 1, 2, 0,
2 min read
Sort a linked list of 0s, 1s and 2s Given a linked list where nodes can contain values 0s, 1s, and 2s only. The task is to sort 0s, 1s, and 2s in the linked list such that all zeros segregate to the head side, 2s at the end of the linked list, and 1s in the middle of 0s and 2s.Examples:Input: head: 1 â 2 â 2 â 1 â 2 â 0 â 2 â 2 Output
15+ min read
Javascript Program For Sorting A Linked List Of 0s, 1s And 2s By Changing Links Given a linked list of 0s, 1s and 2s, sort it.Examples:Input: 2->1->2->1->1->2->0->1->0Output: 0->0->1->1->1->1->2->2->2The sorted Array is 0, 0, 1, 1, 1, 1, 2, 2, 2.Input: 2->1->0Output: 0->1->2The sorted Array is 0, 1, 2Method 1: There is
3 min read