Re: [algogeeks] Re: Return index of first mismatch bracket "(" or ")"

2011-12-22 Thread atul anand
@Terence : got it :) :) ...inc/dec wont work On Thu, Dec 22, 2011 at 10:57 AM, Terence wrote: > Then what's your output for test case "()(()"? > > > On 2011-12-22 12:45, atul anand wrote: > > i guess there is no need of stack , we can take a variable say top; > > increment top when open bracket

Re: [algogeeks] Re: Return index of first mismatch bracket "(" or ")"

2011-12-22 Thread atul anand
got it :) On Thu, Dec 22, 2011 at 10:57 AM, Terence wrote: > Then what's your output for test case "()(()"? > > > On 2011-12-22 12:45, atul anand wrote: > > i guess there is no need of stack , we can take a variable say top; > > increment top when open bracket occur "(" and decrement when close

Re: [algogeeks] Re: Return index of first mismatch bracket "(" or ")"

2011-12-22 Thread atul anand
@venky : u call this code??? On Thu, Dec 22, 2011 at 7:44 PM, venky wrote: > #include#include#define maxsize 100 > struct stack{ int A[maxsize]; int top;}; struct stack s;void > push(int > index){ s.top++;if(s.top==maxsize) { > printf("cannot be pushed"); } > else{

Re: [algogeeks] Re: Return index of first mismatch bracket "(" or ")"

2011-12-22 Thread Terence
Then what's your output for test case "()(()"? On 2011-12-22 12:45, atul anand wrote: i guess there is no need of stack , we can take a variable say top; increment top when open bracket occur "(" and decrement when close bracket ")" occurs. keep track of first close bracket mismatch i.e when

Re: [algogeeks] Re: Return index of first mismatch bracket "(" or ")"

2011-12-22 Thread Terence
And I think the comparing between first unmatched open/close bracket index is not needed. If we found an unmatched close bracket (ie. the stack is empty when encounter a close bracket), we could return current index immediately, since all open brackets before that position are matched and popp

Re: [algogeeks] Re: Return index of first mismatch bracket "(" or ")"

2011-12-21 Thread atul anand
i guess there is no need of stack , we can take a variable say top; increment top when open bracket occur "(" and decrement when close bracket ")" occurs. keep track of first close bracket mismatch i.e when top is zero and current bracket is ")". if top!=0 report min(index,top); On Tue,