[algogeeks] Nested Function C

2012-10-02 Thread rahul sharma
Guys i have read that we cant define function in another function in c Then why this followung program running fine on gcc #include void abc() { printf("bac"); void abf() { printf("bas"); getchar(); } } int main() { abc(); getch

Re: [algogeeks] finding element in array with minimum of comparing

2012-10-02 Thread atul anand
@umer : how no. of comparison are reduced to half by moving both sidesyou have 2 if condition inside, so you are making 2 comparisons at each iteration + n/2 comparison for while loop so number of comparisons are n+n/2 On 10/2/12, Umer Farooq wrote: > why don't we try it from both ends ... so

Re: [algogeeks] finding element in array with minimum of comparing

2012-10-02 Thread Dave
@Umer: I say that you forgot to increment i and decrement j in the loop. But you don't need any loop-counting comparisons at all. Dave On Tuesday, October 2, 2012 3:36:58 AM UTC-5, Umer Farooq wrote: > why don't we try it from both ends ... something like this: > > int i = 0; j = size-1; > >

Re: [algogeeks] Print Permutaion of a given String

2012-10-02 Thread Chaitanya Gupta
The following link might help you: http://www.geeksforgeeks.org/archives/767 On Tue, Oct 2, 2012 at 1:03 AM, rahul sharma wrote: > > -- > You received this message because you are subscribed to the Google Groups > "Algorithm Geeks" group. > To post to this group, send email to algogeeks@googl

Re: [algogeeks] finding element in array with minimum of comparing

2012-10-02 Thread Umer Farooq
why don't we try it from both ends ... something like this: int i = 0; j = size-1; while (i != j) { if (arr[i] == elem) return arr[i]; if (arr[j] == elem) return arr[j]; } this way, we have eliminated half of the comparisons in for loop? What do you guys say? On Tue

[algogeeks] Re: finding element in array with minimum of comparing

2012-10-02 Thread Dave
@Rafi: Try this: int arrExsits( int* arr, int size, int elem) { int temp = arr[0]; arr[0] = elem; while( arr[--size] != elem ); arr[0] = temp; return a[size] == elem ? size : -1; } n+1 comparisons, and it leaves the array unaltered. Dave On Sunday, September 30, 2012 4:27:2

Re: [algogeeks] finding element in array with minimum of comparing

2012-10-02 Thread rafi
Vikas is right! while (n) is equal to (while n!=0) you have 2n compares! בתאריך יום שני, 1 באוקטובר 2012 12:12:21 UTC+2, מאת vikas: > > still there is no improvement, compiler will generate the code to compare > with zero here. what you have accomplished is , hide it from human eyes > > On Monday