# balanced paranthesis

can anyone tell me a c program to check whether paranthesis, are balanced & another to perform mergesort.
thanks

• : can anyone tell me a c program to check whether paranthesis, are
: balanced & another to perform mergesort.
: thanks
:
To check for balanced paretheses, maintain a stack. push when you get an open parenthesis, pop when you get a close. The stack pointer should be exactly zero at end, and should never go below zero.

to to a mergesort

void mergesort(void *data, size_t elsze, size_t N, int (*comp)(const void *e1, const vod *e2))
{
/* code goes here */
}

To mergesort a list of one is trivial. To mergesort a list of two sorted lists, declare a temporary buffer to hold your results. Step through the two lists, putting the lower into your temporary, and incrementing your travelling ponter, until you have reached the end of both lists. The temporary is now sorted. Swap the temporary with your original data, and delete the temporary.

So start by mergesorting lists of two, then unify the lists, going up recursively. The last list may be shorter than the others. This is no problem.

• : : can anyone tell me a c program to check whether paranthesis, are
: : balanced & another to perform mergesort.
: : thanks
: :
: To check for balanced paretheses, maintain a stack. push when you
: get an open parenthesis, pop when you get a close. The stack pointer
: should be exactly zero at end, and should never go below zero.
:
: to to a mergesort
:
: void mergesort(void *data, size_t elsze, size_t N, int (*comp)(const
: void *e1, const vod *e2))
: {
: /* code goes here */
: }
:
: To mergesort a list of one is trivial. To mergesort a list of two
: sorted lists, declare a temporary buffer to hold your results. Step
: through the two lists, putting the lower into your temporary, and
: incrementing your travelling ponter, until you have reached the end
: of both lists. The temporary is now sorted. Swap the temporary with
: your original data, and delete the temporary.
:
: So start by mergesorting lists of two, then unify the lists, going
: up recursively. The last list may be shorter than the others. This
: is no problem.
:
: Thanks it was a great help.