Linked list problems............................................
|
|---|
Reversing a linked list. Solutions...
|
Sorted Insertion of a node into linked list. Solution...
|
Deletion of node from linked list. Solution...
|
Finding Nth element in a Linked List. Solution...
|
| Binary search method. Solution... |
| Generate mirror image tree of given tree. Solution... |
Binary search algorithm
{
low = 0
high = N
while (low < high)
{
mid = (low + high)/2;
if (A[mid] < value)
low = mid + 1;
else
//can't be high = mid-1: here A[mid] >= value,
//so high can't be < mid if A[mid] == value
high = mid;
}
// high == low, using high or low depends on taste
if (low < N) and (A[low] == value)
return low // found
else
return -1 // not found