2. Google dutch national flag problem. This has already been discussed. 3. *printLevelorder(tree)*
bool ltr = 0; for d = 1 to height(tree) printGivenLevel(tree, d, ltr); ltr ~= ltr /*flip ltr*/ Function to print all nodes at a given level *printGivenLevel(tree, level)* if tree is NULL then return; if level is 1, then print(tree->data); else if level greater than 1, then if(rtl) printGivenLevel(tree->right, level-1, ltr); printGivenLevel(tree->left, level-1, ltr); else printGivenLevel(tree->left, level-1, ltr); printGivenLevel(tree->right, level-1, ltr); Perform normal level order traversal but after each level, invert the direction of traversal On Sun, Aug 22, 2010 at 9:47 AM, luckyzoner <luckyzo...@gmail.com> wrote: > to traverse the tree in a spiral manner... > 1. Insert the root into stack. > 2. then in a loop check not both stack and queue are empty > 3. { > while(stack not empty) > { > node =pop(stack); > cout<<node->info; > insertintoqueue(node->left); > insertintoqueue(node->right); > } > > while(queue not empty) > { > node = dequeue(queue); > cout<<node->info; > > push(node->left); > push(node->right); > > } > } > > > On Aug 22, 6:41 am, Aravind Prasad <raja....@gmail.com> wrote: > > can anyone provide the correct and full logic for printing BST > > spirally .. > > > > consider a tree > > > > a > > / \ > > b c > > / \ / \ > > d e f g > > > > output==>> abcgfeh > > > > here my doubt is ==>> > > > > how to find the level at wihich we are present (considering we are > > using a stack for even levels and queue for odd levels) > > > > On Aug 21, 9:50 am, Stanley Cai <stanley.w....@gmail.com> wrote: > > > > > this one is not very right... > > > > > public void solution(String str) { > > > > > int t = Integer.parseInt(str, 2); > > > > > System.out.printf(Integer.toBinaryString((int)((1l<<32) - t))); > > > > > } > > > > > Still for this issue, it could be hard if the string is very long, > length is > > > more than 32 > > > > > On Fri, Aug 20, 2010 at 6:46 PM, GOBIND KUMAR <gobind....@gmail.com> > wrote: > > > > This is the code for question no-4 > > > > > > #include<iostream> > > > > #include<conio.h> > > > > using namespace std; > > > > int main(){ > > > > char str[20]; > > > > char *sp=str; > > > > int n=0; > > > > int count=0;int carry=1; > > > > gets(str); > > > > //cout<<"\n"<<str<<"\n"; > > > > while(*sp!='\0'){ > > > > *sp=(*sp=='1')?'0':'1'; > > > > sp++; > > > > count++; > > > > } > > > > //cout<<"\n"<<str; > > > > sp--; > > > > if(*sp=='1'){ > > > > *sp='0'; > > > > carry=1; > > > > } > > > > else { > > > > *sp='1'; > > > > cout<<"\n"<<str; > > > > getch(); > > > > return 0; > > > > } > > > > sp--; > > > > while(count && carry){ > > > > if(*sp=='1'){ > > > > *sp='0'; > > > > carry=1; > > > > } > > > > else{ > > > > *sp='1'; > > > > carry=0; > > > > } > > > > sp--; > > > > count--; > > > > } > > > > cout<<"\n"<<str; > > > > getch(); > > > > return 0; > > > > > > } > > > > > > -- > > > > You received this message because you are subscribed to the Google > Groups > > > > "Algorithm Geeks" group. > > > > To post to this group, send email to algoge...@googlegroups.com. > > > > To unsubscribe from this group, send email to > > > > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > <algogeeks%2bunsubscr...@googlegroups .com> > > > > . > > > > For more options, visit this group at > > > >http://groups.google.com/group/algogeeks?hl=en. > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algoge...@googlegroups.com. > To unsubscribe from this group, send email to > algogeeks+unsubscr...@googlegroups.com<algogeeks%2bunsubscr...@googlegroups.com> > . > For more options, visit this group at > http://groups.google.com/group/algogeeks?hl=en. > > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algoge...@googlegroups.com. To unsubscribe from this group, send email to algogeeks+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.