Insert in a sorted linked list

Given a linked list, with all the nodes in sorted order. Write a function that inserts a new integer in the sorted manner. i.e If the list is as given below: 3 -> 6 -> 9 -> 10 -> 15 And if you want to insert 8 in this list, it should be inserted as […]

Sorting a binary array (which has only 0 & 1)

Given an array which has only 0’s and 1’s. Write an algorithm which will sort this array. (i.e separate 0’s and 1’s by bringing 0’s before 1’s). Input Array: {0, 1, 1, 0, 0, 0, 0, 1, 1, 0} Output Array: {0, 0, 0, 0, 0, 0, 1, 1, 1, 1}

Shift elements in the array forward by k places

Given an array of m elements and an integer k ( total size of array >= m+k), . Write code to shift all the elements of array forward by k positions. For example: If k = 2 and the Input array is as given below, the the output array should be: The extra spaces will […]

Inorder successor of node in a Binary Tree

Given a pointer to the node in a binary tree, write code to find its inorder successor. You may assume each node to also have a pointer to the parent node (along with pointer to right and left sub-trees). Hence, the structure of Node will be struct Node { int data; Node* lptr; // pointer […]