i thought of this code......i think it should work.....correct me if i am wrong
depth=0;max=0; while(c=getchar()!=EOF) { if(c== '{' ) { depth+=1 if(depth>max) max=depth; } else if(c== '}' ) { depth-=1; } } On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain <sandeep6...@gmail.com> wrote: > If we just have to give the depth as in count then, I believe we can use > stack to push/pop curly braces. While maintaining the maximum depth observed > And if we have to display/print line numbers or code itself, then > converting the code in a tree structure should help. > Each node can contain the line/col position of starting/closing braces. > Each node will have its nested braces as child nodes. > > PS: In either case make sure you ignore comments and strings literals > > > Regards, > Sandeep Jain > > > > > On Tue, Jul 12, 2011 at 4:43 PM, shilpa gupta <shilpagupta...@gmail.com>wrote: > >> Write down the c code for finding out the maximum scope depth in a c >> code. A scope >> depth is increased by one with every '{' and decreases by one with >> every '}' >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@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. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@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. > On Tue, Jul 12, 2011 at 4:55 PM, Sandeep Jain <sandeep6...@gmail.com> wrote: > If we just have to give the depth as in count then, I believe we can use > stack to push/pop curly braces. While maintaining the maximum depth observed > And if we have to display/print line numbers or code itself, then > converting the code in a tree structure should help. > Each node can contain the line/col position of starting/closing braces. > Each node will have its nested braces as child nodes. > > PS: In either case make sure you ignore comments and strings literals > > > Regards, > Sandeep Jain > > > > > On Tue, Jul 12, 2011 at 4:43 PM, shilpa gupta <shilpagupta...@gmail.com>wrote: > >> Write down the c code for finding out the maximum scope depth in a c >> code. A scope >> depth is increased by one with every '{' and decreases by one with >> every '}' >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Algorithm Geeks" group. >> To post to this group, send email to algogeeks@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. >> >> > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@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. > -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to algogeeks@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.