joyboyhardik
BAN USER
Comments (3)
Reputation 50
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
5
of 5 vote
int CalculateDifference(Node n){
int sum = 0, flip = 1, size;
if(null == n) {
return sum;
}
q.add(n);
size = q.size();
while(size != 0) {
for(int i = 0;i<size;i++) {
sum = sum + q.remove().data * flip;
if(n.hasLeft())
q.add(n.left);
if(n.hasRight())
q.add(n.right);
}
size = q.size();
flip = flip* 1;
}
return sum;
}

joyboyhardik
September 28, 2013 Comment hidden because of low score. Click to expand.
1
of 1 vote
struct node *sortlist(struct node *root) {
struct node *middle = NULL, *later = NULL, *parent = NULL, *pwalk2 = NULL;
if(NULL == root) {
return root;
}
middle = root;
while(middle>next) {
if(middle>data <= middle>next>data)
middle = middle>next;
else
break;
}
if(middle>next) {
later = middle>next;
/*special case when node goes on top*/
if(later>data < root>data) {
if(later>next != NULL)
middle>next = later>next;
else {
middle>next = NULL;
later>next = middle;
return later;
}
later>next = root;
root = later;
}
/*goes in somewhere middle*/
parent = root;
while(middle>next) {
pwalk2 = parent>next;
while(pwalk2 != middle>next) {
later = middle>next;
if(later>data <= pwalk2>data) {
if(later>next != NULL)
middle>next = later>next;
else
middle>next = NULL;
parent>next = later;
later>next = pwalk2;
break;
}
parent = pwalk2;
pwalk2 = pwalk2>next;
}
}
return root;
} else {
return root;
}
}
 joyboyhardik September 28, 2013Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
 joyboyhardik October 08, 2013