Binary Search Tree, height [closed] - c++

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
this is my height function in bst. cpp
int IntBinaryTree::getHeight(TreeNode * nodePtr)
{
if(nodePtr = NULL)
return 0;
else
return (max(1+getHeight(nodePtr->left), 1+getHeight(nodePtr->right)));
}
When I call it in main(). I got an error.
this is my main()
int main {
IntBinaryTree tree;
....
tree. getHeight();
return 0;
}

You didn't say what error, but looks like changing:
if(nodePtr = NULL)
to
if(nodePtr == NULL)
^^
is what you need.

Related

Why this code gives run time error on mid calculation? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
int main() {
int start = 0;
int end = 2;
int ret1 = 0;
int mid = start + (end-start)/2;
ret1 = mid;
return ret1;
}
Why is this code giving runtime error?
https://ideone.com/iAdQO0
A nonzero return code from main() indicates an error to many operating systems.
Because any return from main that is not 0 indicates a runtime error.

For loop only executing once? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 1 year ago.
Improve this question
I don't know if I'm just being stupid, but Visual Studio says that my for loop is only executing once, and it does seem to be the case. However I can't figure out why. I'd really appreciate it if anyone could tell me what I'm doing wrong.
for (int i = (nbToVerify - 1); i == 1; i--)
{
if (nbToVerify % i == 0)
{
nbIsPrime = false;
break;
}
else
{
nbIsPrime = true;
}
}
Thanks!
i == 1 should be i != 1, that's it.

Variable not declared in this scope [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
Sorry if this is very basic question. I'm a Java guy and new to CPP. As per logic everything looks fine to me. But the compiler still throwing the error
"result was not declared in this scope " What might be the reason ?
And line causing error is
ns1__changePinTestResponse* result= soap_new_ns1__ChangePinResponse(this);
Here are my codes.
int ATLServerService::changePinTest(_ns1__changePinTest *ns1__changePinTest, _ns1__changePinTestResponse *ns1__changePinTestResponse)
{
LOG_DEBUG_MSG("ATLServerService::changePassword()");
char* accountID = (char*)ns1__changePinTest->accountID.c_str();
int accountPin = ns1__changePinTest->accountPin;
char* newPassword = (char*)ns1__changePinTest->newPassword.c_str();
char* yourSerialNumber = (char*)ns1__changePinTest->yourSerialNumber.c_str();
tfaddress transactionFileAddress;
int returnValue = 0;
returnValue = Account::changePassword(toteGateway, myGdi,accountID, accountPin,
newPassword, yourSerialNumber, &transactionFileAddress);
ns1__changePinTestResponse* result= soap_new_ns1__ChangePinResponse(this);
result->code = returnValue;
if (returnValue == ESUCCESS) {
result->message = &SUCCESS;
result->transactionFileAddress = transactionFileAddress;
} else {
result->message = &ERROR;
}
ns1__changePinTestResponse->changePinTestReturn= result;
return SOAP_OK;
}
You are missing the first underscore. It should be:
_ns1__changePinTestResponse
not
ns1__changePinTestResponse

std::vector<std::tuple in for - cannot get values [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
with tuple i have this code
for (std::vector<std::tuple<uint32, std::string, uint32> >::const_iterator ixn = messages.begin(); ixn != messages.end(); ++ixn)
{
if (std::get<0>(ixn) == user->getID() && std::get<1>(ixn) == msg && std::get<2>(itr) > time)
{
//some doin
}
}
and it sayin
no matching function for call to ‘get(std::vector<std::tuple<long unsigned...
You need to dereference your iterator using (*ixn). Also your last iterator is called itr instead of ixn.
for (std::vector<std::tuple<uint32, std::string, uint32> >::const_iterator ixn = messages.begin(); ixn != messages.end(); ++ixn)
{
if (std::get<0>(*ixn) == user->getID() && std::get<1>(*ixn) == msg && std::get<2>(*ixn) > time)
{
//some doin
}
}

Why do i get this wrong result? [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 8 years ago.
Improve this question
I'M trying to make a code that is able to increase int 'd' by one each time the a+b reach 20.
and if there still any number less than 20 then this will be the int 'c'.
but instead of getting the right result in my next program which is
49-0
i get this wrong answer
47-40
what should i do ?
#include <iostream>
using namespace std;
int main(){
int a=50;
int b=18;
int c=a+b;
int d=0;
int i;
for(i=0;i<c;i++)
{
while(c>20)
{
d+=1;
c=c-20;
break;
}}
cout<<d<<"-"<<c;
return 0;
}
The problem is in your while loop:
while(c > 20)
{
d+=1;
c=c-20;
break;
}
The loop will only execute once because of your break statement.