dronzer709
BAN USERThis solution will return '0' all the time...
The problem with is as follows:
if (mid - left < a[mid] - a[left])
binary_search(a, left, mid); <<<< You are not returning the value from stack
else
binary_search(a, mid, right); <<<< You are not returning the value from stack
The solution is as follows:
if (mid - left < a[mid] - a[left])
return (binary_search(a, left, mid));
else
return (binary_search(a, mid, right));
int GCD(int a, int b)
{
if(a == 0)
return b;
while (b != 0)
{
if(a > b)
a = a - b;
else
b = b - a;
}
return a;
}
Yes, as abstract/base class will be constructed when an object of derived class is constructed, hence at that time the abstract/base class constructor will set the vtable pointer to its own vtable.
- dronzer709 May 20, 2012Yes, as abstract/base class will be constructed when an object of derived class is constructed, hence at that time the abstract/base class constructor will set the vtable pointer to its own vtable.
- dronzer709 May 20, 20121) malloc: you cannot use delete with malloc, as no constructor is called during memory allocation and while delete is used on that memory it will call destructor which will lead to seg fault.
2)new: you can use either delete or free. But the problem with using free is that the class desctructor is not called and hence there will be problems later on.
Hence try to stick with malloc-free and new-delete
1) malloc: you cannot use delete with malloc, as no constructor is called during memory allocation and while delete is used on that memory it will call destructor which will lead to seg fault.
2)new: you can use either delete or free. But the problem with using free is that the class desctructor is not called and hence there will be problems later on.
Hence try to stick with malloc-free and new-delete
It will print binary equivalent of the number
- dronzer709 May 19, 2012Can you place the algorithm over here, I am having confusion for the recursion.
- dronzer709 June 21, 2011Also it is single linked list, correct?
- dronzer709 June 21, 2011Hmm because with reverse is easy and can be done with O(N) n constant space, but without reverse it is interesting, if I think of anything will let you know...:)
- dronzer709 June 21, 2011So you want to add two list without recursion & reverse?
- dronzer709 June 21, 2011I think the best is the XOR implementation, reason being:
when u use temp variable memory is used more and you access the register every now and then, when you are doing arithmetic operation you incure the overhead of ALU (hardware circuit) but bitwise operation is manipulation of bits at hardware level as the bits are already in the register which is fastest of three.
int FindDepth(Node *node)
{
int leftDepth, rightDepth;
if (node == NULL)
return 0;
else{
leftDepth = FindDepth(node->left);
rightDepth = FindDepth(node->right);
if (leftDepth > rightDepth)
return (leftDepth+1);
else
return (rightDepth+1);
}
}
I think pre-order traversal will help here...Not sure though
- dronzer709 March 01, 2011
In-order and then check current with next value. If current is greater then next then not sorted or else it is.
- dronzer709 September 08, 2014