vagrawal13
BAN USERalso after while loop , *n = NULL else traversal will give runtime error
- vagrawal13 June 27, 2012void arrange(NODEPTR* m){
if(*m == NULL){
cout << "List is empty" << endl;
return;
}
NODEPTR init,temp,p,q;
init = (isVowel((*m)->data)) ? (*m) : NULL;
q = *m;
p = q->link;
while(p != NULL){
traverse(*m);
if(isVowel(p->data)){
//adding at beginning
if(init == NULL){
temp = p->link;
p->link = *m;
q->link = temp;
*m = p;
}
else{
temp = p->link;
p->link = init->link;
q->link = temp;
init->link = p;
}
init = p;
}
else
q = p;
p = q->link;
}
}
Let n be the no of iterations and initial stack be numbered as :
A 1
B 2
C 3
D 4
E 5
mid position = 3
Let "pos" be the position which is at "mid" after 'n' iterations. Then we have
(pos + 3*n)%5 = 3
3 in LHS is because 3 positions are shifted in each iterations and 3 in RHS is for mid.
- vagrawal13 June 25, 2012
- vagrawal13 July 03, 2012