aimjwizards
BAN USERstruct Node{
string name;
int weight;
Node* left;
Node* right;
};
void recFindMinWeight(Node* root, int &weight, Node *&minNode) {
if (root) {
return;
}
if (root->left && root->right) {
int current = root->weight;
current+= root->left->weight;
current+= root->right->weight;
if (current< weight) {
weight = current;
minNode = root;
}
}
recFindMinWeight(root->left, weight, minNode);
recFindMinWeight(root->right, weight, minNode);
}
Node* findMinWeight(Node* root) {
int weight = INT_MAX;
Node * minNode = root;
recFindMinWeight(root, weight, minNode);
if (weight == INT_MAX) {
return NULL;
} else {
return minNode;
}
}
I think some of your code is redundant.
while(*fastPtr){
if(isConsonant(*fastPtr))
fastPtr++;
else{
if(isVowel(*fastPtr)){
char temp = *fastPtr;
char *p = fastPtr;
while(p != slowPtr){
*p = *(p-1);
--p;
}
*slowPtr = temp;
}
++slowPtr;
++fastPtr;
}
}
- aimjwizards March 24, 2013#include <iostream>
#include <algorithm>
using namespace std;
int multiply(int A[], int lenA, int B[], int lenB) {
int len = max(lenA, lenB);
int sum = 0;
for (int i=0; i<len; i++) {
sum += A[i%lenA]*B[i%lenB];
}
return sum;
}
int main(void) {
int A[] = {1, 2, 3, 4, 5};
int B[] = {2, 1};
int lenA = sizeof(A)/sizeof(int);
int lenB = sizeof(B)/sizeof(int);
cout << multiply(A, lenA, B, lenB) << endl;
return 0;
}
What if it's not a square matrix?
- aimjwizards March 05, 2013
since we are comparing the word list against one single word, the prefix tree is not that straightforward as the string representation.
- aimjwizards April 07, 2013