[algogeeks] # References !!!!

2011-07-12 Thread Ashish kumar Jain
#includeiostream using namespace std; int main(void) { int a=10 ,b=4; int c=a; cout\n-a; a+=20; cout\n-c; // //Add your code here. /*/ cout\n-c; c=999;

[algogeeks] # References !!!!

2011-07-12 Thread Ashish
#includeiostream using namespace std; int main(void) { int a=10 ,b=4; int c=a; cout\n-a; a+=20; cout\n-c; // //Addyour code here. /*/ cout\n-c; c=999;

Re: [algogeeks] # References !!!!

2011-07-12 Thread sunny agrawal
Once a reference is initialized to an object, it cannot be changed to refer to another object. Ref. Bruce Eckel - ch11 So its Not possible -- Sunny Aggrawal B-Tech IV year,CSI Indian Institute Of Technology,Roorkee -- You received this message because you are subscribed to the Google Groups

[algogeeks] Re: C OUTPUT HELP

2011-07-12 Thread Abhi
PROBLEM 2: First all the expressions are evauated from right to left in printf() and then results printed with tha final value of i. -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit

Re: [algogeeks] # References !!!!

2011-07-12 Thread Anand Saha
Yep, and http://www.parashift.com/c++-faq-lite/references.html#faq-8.5 -- On Tue, Jul 12, 2011 at 12:50 PM, sunny agrawal sunny816.i...@gmail.comwrote: Once a reference is initialized to an object, it cannot be changed to refer to another object. Ref. Bruce Eckel - ch11 So its Not

Re: [algogeeks]

2011-07-12 Thread Anand Saha
Also - new and delete are typesafe, hence better. (malloc returns void*) - new gives you the feature of placement new, which allows you create an object in a pre-determined location, which is helpful I think in device drivers programming... -- On Tue, Jul 12, 2011 at 10:39 AM, sagar pareek

Re: [algogeeks] Re: C OUTPUT HELP

2011-07-12 Thread saurabh singh
For 1st problem learn the concepts of linking.Scanf hasn't been required to link yet in the main. So during compling the program doesn't give any special treatment to scanf. check this, #includestdio.h int charu(int x); int charu(int x) { return x; } main() { int charu=67; int scanf=78; //int

Re: [algogeeks] Re: C OUTPUT HELP

2011-07-12 Thread Anand Saha
But this works, where I have both the variable name and function name used: #includestdio.hint charu(int x);int charu(int x) { return x; } main(){* int a = charu(45); int charu = a;* int scanf=78; //int printf=45; int getchar=6;

Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread Anand Saha
On Tue, Jul 12, 2011 at 1:29 AM, nicks crazy.logic.k...@gmail.com wrote: *PROBLEM 3.* * * #includestdio.h main() { enum {low='a',high='b'}tag; char try=low; printf(Size=%d,sizeof(tag)); switch (try) { case 'a':printf(aaa);break; case 'b':printf(bbb); case 'c':printf(ccc); }

Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread nicks
@anandregarding problem 2 i agree with you and observed the samebut that gives me the feel that the compiler in working in the interprating manner though it doesn't...btw thanks for pointing it out. and in problem 3 what i understood after reading with what you wrote is that size

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread sagar pareek
One solution can be in one traversal :- take an example:- char str[]=hello my friends; int i=strlen(str),j=i; char *srt1=malloc(sizeof(char)*i); 1. start from end of string (while i=0,i--) 2. whenever u find any space do a. strcat(srt1,srt[i]); b. srt[i]='\0'; d. srt[j-i]='space';

Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread Anand Saha
On Tue, Jul 12, 2011 at 2:36 PM, nicks crazy.logic.k...@gmail.com wrote: and in problem 3 what i understood after reading with what you wrote is that size of tag will remain sizeof(int) irrespective of the number of constants in it.correct me if i am wrong !! Right. -- -- You received

Re: [algogeeks]

2011-07-12 Thread Abhi
I thought malloc returned char* ! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/n-KMvxWiJs4J. To post to this group, send email to

Re: [algogeeks] Re: Puzzle

2011-07-12 Thread sagar pareek
@Tushar Bindal No need of long calculations :) here is a shortcut, actually in O(1) time :) for calculating chances of any two entities to collide in given different species is just take underoot of it. here underoot of 365 is approx 19.he he enjoy the solution. For more details just go

Re: [algogeeks] Re: sbtration

2011-07-12 Thread hary rathor
how it can done without using any arithmetic operation ? -- 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

Re: [algogeeks] Re: sbtration

2011-07-12 Thread vaibhav shukla
@hary check sunny's solution and for '+' do with bitwise operators. On Tue, Jul 12, 2011 at 4:11 PM, hary rathor harry.rat...@gmail.com wrote: how it can done without using any arithmetic operation ? -- You received this message because you are subscribed to the Google Groups Algorithm

Re: [algogeeks] Re: Yahoo Question

2011-07-12 Thread Abhi
Can anyone give an insight into the way XOR operations are used for swapping two variables? -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/ZJ_fiB6VmlQJ. To

Re: [algogeeks] Re: Yahoo Question

2011-07-12 Thread atul purohit
@abhi For XOR a=a^b; b=a^b; a=a^b; On Tue, Jul 12, 2011 at 4:26 PM, Abhi abhi123khat...@gmail.com wrote: Can anyone give an insight into the way XOR operations are used for swapping two variables? -- You received this message because you are subscribed to the Google Groups Algorithm

[algogeeks] microsoft ques

2011-07-12 Thread shilpa gupta
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

Re: [algogeeks] microsoft ques

2011-07-12 Thread Sandeep Jain
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

[algogeeks] Re: O(n) Time is the problem. ..

2011-07-12 Thread anonymous procrastination
@Dave Can you please explain through example. Suppose the set is {0,1,2,3,5,6} Then how this solution proceeds. I am partially getting the logic you explained but need to see an example. Thanks!! -- You received this message because you are subscribed to the Google Groups Algorithm Geeks

[algogeeks] Re: MS: BST

2011-07-12 Thread Gopi
@Anurag: Can you please elaborate your algo. Thanks Gopi -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To view this discussion on the web visit https://groups.google.com/d/msg/algogeeks/-/CIZEYDMXpX8J. To post to this group, send email to

[algogeeks] Re: MS: BST

2011-07-12 Thread ●αηυяαg ∩ ℓιƒє ≈ Φ
In order traversal results in a sorted list of elements of BST say [a,b,c,d,e]. make another array containing [k-a,k-b,k-c,k-d,k-e].Reverse yeilds [k-e,k-d,k-c,k-b,k-a]. Now apply the standard merge function (Merge sort). on [a,b,c,d,e] [k-e,k-d,k-c,k-b,k-a]. Finally adjacent equal entries

Re: [algogeeks] microsoft ques

2011-07-12 Thread nicks
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(depthmax) max=depth; } else if(c== '}' ) { depth-=1; } } On Tue, Jul 12,

Re: [algogeeks] # References !!!!

2011-07-12 Thread Ashish kumar Jain
You think so! Time to think again. :) #includeiostream using namespace std; int main(void) { int a=10 ,b=4; int c=a; cout\n-a; a+=20; cout\n-c; // //Addyour code here. *(unsigned long*)(((unsigned

Re: [algogeeks] microsoft ques

2011-07-12 Thread Vandana Bachani
You have the right braces missing, it would result in a 0 depth for all cases. (Precedence of != is greater than =) On Tue, Jul 12, 2011 at 5:41 PM, nicks crazy.logic.k...@gmail.com wrote: i thought of this code..i think it should work.correct me if i am wrong depth=0;max=0;

Re: [algogeeks] # References !!!!

2011-07-12 Thread Anand Saha
Which compiler? http://www.ideone.com/7nnse -- On Tue, Jul 12, 2011 at 5:42 PM, Ashish kumar Jain akjlucky4...@gmail.comwrote: You think so! Time to think again. :) #includeiostream using namespace std; int main(void) { int a=10 ,b=4; int c=a; cout\n-a;

Re: [algogeeks] microsoft ques

2011-07-12 Thread nicks
my bad...that should be understood.. On Tue, Jul 12, 2011 at 5:45 PM, Vandana Bachani vandana@gmail.comwrote: You have the right braces missing, it would result in a 0 depth for all cases. (Precedence of != is greater than =) On Tue, Jul 12, 2011 at 5:41 PM, nicks

Re: [algogeeks] # References !!!!

2011-07-12 Thread Ashish kumar Jain
Dev C++ On Tue, Jul 12, 2011 at 5:48 PM, Anand Saha anands...@gmail.com wrote: Which compiler? http://www.ideone.com/7nnse -- On Tue, Jul 12, 2011 at 5:42 PM, Ashish kumar Jain akjlucky4...@gmail.com wrote: You think so! Time to think again. :) #includeiostream using namespace

Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread Kamakshii Aggarwal
for the second problem,y should the answer be 3 1?.it should be 3 2 and it is working fine on dev c++ giving 3 2. On Tue, Jul 12, 2011 at 2:48 PM, Anand Saha anands...@gmail.com wrote: On Tue, Jul 12, 2011 at 2:36 PM, nicks crazy.logic.k...@gmail.com wrote: and in problem 3 what i

Re: [algogeeks] microsoft ques

2011-07-12 Thread nicks
igonre the previous code, here is fully working code..previous one doesn't include check for having { within quotes which should not be counted for scope depth #includestdio.h int main() { int depth=0,max=0; char c,temp; while((c=getchar())!=EOF) { if(c== '{' ) {

Re: [algogeeks] C OUTPUT HELP

2011-07-12 Thread nicks
3 1 is the output which i predicted without running...it is giving 3 3 on gcc and may give 3 2 on dev c++ . output will be compiler dependent as these types of situations are not defined in standards hence implementation dependent..i want someone to explain the output with reference to

Re: [algogeeks] # References !!!!

2011-07-12 Thread Ashish kumar Jain
This is also somewhat compiler dependant as some compilers store references in symbol table while others do so using stack.This one runs on stack fundamentals.This is against C++ standards but this is just a trick for this code on big endian which stores reference on stacks.This won't work for

Re: [algogeeks] microsoft ques

2011-07-12 Thread sunny agrawal
1. what if braces occur in comments and also i think final answer should be 1 less than(dropping { for main()) the final count because there is no meaning of scope depth for a global variable On Tue, Jul 12, 2011 at 6:22 PM, nicks crazy.logic.k...@gmail.com wrote: igonre the previous code,

Re: [algogeeks] microsoft ques

2011-07-12 Thread Aniket Dutta
what happens when to the '{' in comments i guess your program is also counting that.. On Tue, Jul 12, 2011 at 6:22 PM, nicks crazy.logic.k...@gmail.com wrote: igonre the previous code, here is fully working code..previous one doesn't include check for having { within quotes which

Re: [algogeeks] microsoft ques

2011-07-12 Thread Aniket Dutta
for example /* { { } }*/ On Tue, Jul 12, 2011 at 6:36 PM, Aniket Dutta aniketdutt...@gmail.comwrote: what happens when to the '{' in comments i guess your program is also counting that.. On Tue, Jul 12, 2011 at 6:22 PM, nicks crazy.logic.k...@gmail.com wrote: igonre the

Re: [algogeeks] microsoft ques

2011-07-12 Thread Nitish Garg
What about the braces that occur in the functions, I think the scope for different functions should be counted differently and the max given. On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal sunny816.i...@gmail.comwrote: 1. what if braces occur in comments and also i think final answer should

Re: [algogeeks] microsoft ques

2011-07-12 Thread shilpa gupta
i think there is no need of this part else if(c== '}' ) { depth-=1; } than there is no need to find out max also depth will give max itself i think... On Tue, Jul 12, 2011 at 6:32 PM, sunny agrawal sunny816.i...@gmail.comwrote: 1. what if braces occur in comments and

[algogeeks] Image based Problem (Google)

2011-07-12 Thread Navneet Gupta
Given 1000 million x 1000 million image, What information of this image to be stored such that you can find the locations when the given image has modi cations -- Regards, Navneet -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to

Re: [algogeeks] microsoft ques

2011-07-12 Thread sunny agrawal
@Nitish as complete file will be scanned, program is taking care of functions already @shilpa u r wrong !! that part of code is very important else what will be the answer for the following { { } { } { { } } } On Tue, Jul 12, 2011 at 6:39

Re: [algogeeks] microsoft ques

2011-07-12 Thread nicks
@shilpa...absolutely wrong { } { } depth acc. to you is 2...incorrectit is 1 On Tue, Jul 12, 2011 at 6:39 PM, shilpa gupta shilpagupta...@gmail.comwrote: i think there is no need of this part else if(c== '}' ) { depth-=1; } than there is no need to find out max

Re: [algogeeks] microsoft ques

2011-07-12 Thread shilpa gupta
@sunny well this case is not possible i think in any code a braces that are opened should be closed...also On Tue, Jul 12, 2011 at 6:43 PM, sunny agrawal sunny816.i...@gmail.comwrote: @Nitish as complete file will be scanned, program is taking care of functions already @shilpa u r wrong !!

Re: [algogeeks] microsoft ques

2011-07-12 Thread sunny agrawal
@shilpa see some post is hidden click on hide quoted text to see the complete post On Tue, Jul 12, 2011 at 6:46 PM, shilpa gupta shilpagupta...@gmail.comwrote: @sunny well this case is not possible i think in any code a braces that are opened should be closed...also On Tue, Jul 12,

[algogeeks] NVIDIA

2011-07-12 Thread aanchal goyal
why does space allocator malloc()/free() interface use circular link list to store allocated/freed addresses in sorted order in a link list form and not tree(balanced)? To find some address for deletion it needs list traversal which costs O(n) whereas a balanved tree (at cost of extra pointer

Re: [algogeeks] microsoft ques

2011-07-12 Thread shilpa gupta
@sunny k i have seen... On Tue, Jul 12, 2011 at 6:48 PM, sunny agrawal sunny816.i...@gmail.comwrote: @shilpa see some post is hidden click on hide quoted text to see the complete post On Tue, Jul 12, 2011 at 6:46 PM, shilpa gupta shilpagupta...@gmail.comwrote: @sunny well this case

[algogeeks] Search node in a binary tree

2011-07-12 Thread anonymous procrastination
Hello, Suppose you have to search a particular node in a binary tree. The code is quite simple. Pick up any traversal and see if any node matches the value. Doubt I have is that how to pull out of the recursive function at the instant node is found. In iterative algos we use a break. Here I can

Re: [algogeeks] Search node in a binary tree

2011-07-12 Thread sunny agrawal
i think Return statement will do the job :) On Tue, Jul 12, 2011 at 6:58 PM, anonymous procrastination opamp1...@gmail.com wrote: Hello, Suppose you have to search a particular node in a binary tree. The code is quite simple. Pick up any traversal and see if any node matches the value.

[algogeeks] Overview of the New C++ (C++0x) by Scott Meyers

2011-07-12 Thread yash
Hi, Pls let me know if any one have below ebooks : 1)Overview of the New C++ (C++0x) by Scott Meyers 2)Programming Pearls (2nd edition) by Jon Bentley. Thanks Yash -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

[algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Don
There is no reason to use recursion to search a binary tree. Don On Jul 12, 8:28 am, anonymous procrastination opamp1...@gmail.com wrote: Hello, Suppose you have to search a particular node in a binary tree. The code is quite simple. Pick up any traversal and see if any node matches the

[algogeeks] Re: Search node in a binary tree

2011-07-12 Thread bittu
whats the problem with this bool search(root,node) { if(root==node) return 1; else return search(root-left,node)||search(root-right,node); } TC O(N) notify me via mail if anything wrong.? Thanks Shashank CSE,BIT Mesra -- You received this message because you are

Re: [algogeeks] NVIDIA

2011-07-12 Thread ankit sambyal
I think the allocation of address in case of circular linked list is very fast O(1), whereas it takes O(log n) in case of balanced tree. And yes, to find address for deletion in case of circular linked list is expensive... O(n) in worst case. On Tue, Jul 12, 2011 at 6:19 AM, aanchal

Re: [algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
@bittu On 7/12/11, Aniket Dutta aniketdutt...@gmail.com wrote: what will happen if node is not found?. you are not checking it On 7/12/11, bittu shashank7andr...@gmail.com wrote: whats the problem with this bool search(root,node) { if(root==node) return 1; else

Re: [algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
what will happen if node is not found?. you are not checking it On 7/12/11, bittu shashank7andr...@gmail.com wrote: whats the problem with this bool search(root,node) { if(root==node) return 1; else return search(root-left,node)||search(root-right,node); }

Re: [algogeeks] Re: Search node in a binary tree

2011-07-12 Thread ankit sambyal
@Aniket: Just add a condition at the begining: if(root == NULL) 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 algogeeks@googlegroups.com. To unsubscribe from this group, send email to

[algogeeks] Re: Image based Problem (Google)

2011-07-12 Thread bittu
too store this whole image we need 2^70==10^21 bytes size of disk. assuming each pixel take 1 byte . always go metadata for large entities .here metadata includes type(e.g jpeg,bmp,gif etc),size,name,pointer to log file entry etc. Shashank CSE,BIT Mesra -- You received this message because you

Re: [algogeeks] Re: sbtration

2011-07-12 Thread chandy jose paul
correction: if(a/b=1){ return a%b; } else (a/b)*b + a%b; assumption that difference is positive everytime On Tue, Jul 12, 2011 at 10:29 AM, Dave dave_and_da...@juno.com wrote: @Chandy: Let a = 5 and b = 3. Then x = 5 - 3 = (5/3)*3 + 5%3 = 1*3 + 2 = 5. Check? Dave On Jul 11, 11:38 pm,

Re: [algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
@yeah right On Tue, Jul 12, 2011 at 7:36 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Aniket: Just add a condition at the begining: if(root == NULL) return 0; -- You received this message because you are subscribed to the Google Groups Algorithm Geeks group. To post to this

Re: [algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
@bittu On Tue, Jul 12, 2011 at 8:09 PM, Aniket Dutta aniketdutt...@gmail.comwrote: @yeah right On Tue, Jul 12, 2011 at 7:36 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Aniket: Just add a condition at the begining: if(root == NULL) return 0; -- You received this message

Re: [algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Aniket Dutta
sorry @ankit On Tue, Jul 12, 2011 at 8:10 PM, Aniket Dutta aniketdutt...@gmail.comwrote: @bittu On Tue, Jul 12, 2011 at 8:09 PM, Aniket Dutta aniketdutt...@gmail.comwrote: @yeah right On Tue, Jul 12, 2011 at 7:36 PM, ankit sambyal ankitsamb...@gmail.comwrote: @Aniket: Just add a

[algogeeks] Re: sbtration

2011-07-12 Thread bittu
Lets Try For Decimal Integer Number how we add them 1 Add 759 + 674, but “forget” to carry I then get 323 2 Add 759 + 674 but only do the carrying, rather than the addition of each digit I then get 1110 3 Add the result of the first two operations (recursively, using the same process de-

Re: [algogeeks] NVIDIA

2011-07-12 Thread santosh mahto
@aanchal u are correct in first case. deletion is also not O(1). because while freeing we pass the address. so with that address it can directly reach the node which is to be freed. Thanks Santosh On Tue, Jul 12, 2011 at 7:32 PM, ankit sambyal ankitsamb...@gmail.comwrote: I think the

Re: [algogeeks] NVIDIA

2011-07-12 Thread santosh mahto
@aanchal correction: deletion is also O(1); On Tue, Jul 12, 2011 at 8:31 PM, santosh mahto santoshbit2...@gmail.comwrote: @aanchal u are correct in first case. deletion is also not O(1). because while freeing we pass the address. so with that address it can directly reach the node

Re: [algogeeks] Re: Image based Problem (Google)

2011-07-12 Thread santosh mahto
refer Fourier transform and wavelet transform of image On Tue, Jul 12, 2011 at 7:38 PM, bittu shashank7andr...@gmail.com wrote: too store this whole image we need 2^70==10^21 bytes size of disk. assuming each pixel take 1 byte . always go metadata for large entities .here metadata includes

[algogeeks] Re: remove duplicate chars in a string without using extra memory

2011-07-12 Thread bittu
whats the problem ? if no extra memory allowed then can't be done in better then O(nlogn)sorting time O(1) space else it will take O(N) time O(N) Space sorting will change the order but using bitmap or bitarray order will be preserved Thanks Shashank CSE,BIT Mesra -- You received this

[algogeeks] Re: linked list doubt

2011-07-12 Thread bittu
now try how u will remove the loop from linked list Shashank CSE BIT Mesra -- 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] Re: How to store largest N values efficiently

2011-07-12 Thread bittu
John You Can Use MinHeap here is the algo 1) Build a Min Heap MH of the first k elements (arr[0] to arr[k-1]) of the given array. O(k) 2) For each element, after the kth element (arr[k] to arr[n-1]), compare it with root of MH. a) If the element is greater than the root then make it root and

[algogeeks] Re: O(n) Time is the problem. ..

2011-07-12 Thread Dave
@Anonymous: There are 6 numbers in the list. The low order bit of 1^2^3^4^5^6 is 1. The low order bits of the input are 0,1,0,1,1,0. As you read them, make a list pointers to the numbers that have low order bit 0 and another list of pointers that have low order bit 1, and also take their exclusive

Re: [algogeeks] Re: linked list doubt

2011-07-12 Thread Aniket Dutta
@anika: according to satistics we need both n/2 and n/2+1 to find the median from an even set ((n/2)+(n/2+1))/2. but here you cannot do this. so i guess n/2+1 or n/2 both are correct because both contribute equally to calculate median. On 7/12/11, bittu shashank7andr...@gmail.com wrote: now try

[algogeeks] output

2011-07-12 Thread segfault
#includeiostream using namespace std; class x{ public: x() {} int func() const{ coutit is const function\n; } int func() { coutit is simple functin\n; } }; int main() { x a; a.func(); return 0; } why cann't it take const function? explain it -- You received this message because you are

Re: [algogeeks] output

2011-07-12 Thread dheeraj tyagi
const means that it cannot be overloaded..i think due to that this is happening. On Tue, Jul 12, 2011 at 9:26 PM, segfault pawan1991ya...@gmail.com wrote: #includeiostream using namespace std; class x{ public: x() {} int func() const{ coutit is const function\n; } int func() {

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread saurabh singh
and how would strlen compute the length without traversing through the array? On Tue, Jul 12, 2011 at 2:48 PM, sagar pareek sagarpar...@gmail.com wrote: One solution can be in one traversal :- take an example:- char str[]=hello my friends; int i=strlen(str),j=i; char

[algogeeks] Re: Search node in a binary tree

2011-07-12 Thread Don
// Similar to other suggestions, but without tail recursion. ptr search(ptr root, int value) { ptr result = 0; while(root !result) { result = (root-tag == value) ? root : search(root-left, value); root = root-right; } return result; } On Jul 12, 8:28 am,

Re: [algogeeks] output

2011-07-12 Thread Aniket Dutta
@dheeraj: but the prototypes are same. how u are calling it overloading plz explain On 7/12/11, dheeraj tyagi dheeraj2...@gmail.com wrote: const means that it cannot be overloaded..i think due to that this is happening. On Tue, Jul 12, 2011 at 9:26 PM, segfault pawan1991ya...@gmail.com

Re: [algogeeks] output

2011-07-12 Thread Sandeep Jain
*const* in C++ is not exactly same as *final* in java. SO unlike java adding the keyword const to a function does not affect overriding. Infact, adding in C++ const functions == that they will not modify any member of the class. non-const functions cannot be invoked by const objects. Try making

Re: [algogeeks] output

2011-07-12 Thread Aniket Dutta
@sandeep sir: thanx sir for clearing doubt On 7/12/11, Sandeep Jain sandeep6...@gmail.com wrote: *const* in C++ is not exactly same as *final* in java. SO unlike java adding the keyword const to a function does not affect overriding. Infact, adding in C++ const functions == that they will

Re: [algogeeks] Re: sbtration

2011-07-12 Thread Anika Jain
awesum :) thanx all On Tue, Jul 12, 2011 at 8:27 PM, bittu shashank7andr...@gmail.com wrote: Lets Try For Decimal Integer Number how we add them 1 Add 759 + 674, but “forget” to carry I then get 323 2 Add 759 + 674 but only do the carrying, rather than the addition of each digit I then

Re: [algogeeks] questions related to C

2011-07-12 Thread Aniket Dutta
c=a+b then find b=c-a; if this b equals previous one then ok else overflow On 7/9/11, John Hayes agressiveha...@gmail.com wrote: regarding question related to overflow int ovr_sum(int *sum,int a,int b) { *sum=a+b if(*sum0) return -1; //overflow else return 0; //no

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread Navneet Gupta
@Saurabh, just to let you know, compiler actually does that. Without traversing the array (read specifying the array size), you are able to free up all the memory being consumed by simply writing delete []a. On Tue, Jul 12, 2011 at 10:13 PM, saurabh singh saurab...@gmail.com wrote: and how

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread saurabh singh
can strlen do the same job? I doubt...? On Tue, Jul 12, 2011 at 10:51 PM, Navneet Gupta navneetn...@gmail.comwrote: @Saurabh, just to let you know, compiler actually does that. Without traversing the array (read specifying the array size), you are able to free up all the memory being

Re: [algogeeks] output

2011-07-12 Thread dheeraj tyagi
const methods can only be called by constant objects. since in this case the object is not constant it will call the normal method. On Tue, Jul 12, 2011 at 10:24 PM, Aniket Dutta aniketdutt...@gmail.comwrote: @dheeraj: but the prototypes are same. how u are calling it overloading plz

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread Navneet Gupta
My bad in not being clear. I only meant it is possible to know the size of strings without traversing them as compiler does that but I am not sure if is it possible for APIs to do the same. Compiler writes that size in some memory location and use it during delete []str On Tue, Jul 12, 2011 at

Re: [algogeeks] output

2011-07-12 Thread rahul
@dheeraj: const member function can be called by non-constant obj.just remove the non-constant member function...try urself. On Tue, Jul 12, 2011 at 10:59 PM, dheeraj tyagi dheeraj2...@gmail.comwrote: const methods can only be called by constant objects. since in this case the object is

[algogeeks] Re: output

2011-07-12 Thread shiv narayan
cant i invoke both simultaneously?? if i try to make two objects like x const a; x a; then it gives error..can u explain plz. On Jul 12, 9:55 pm, Sandeep Jain sandeep6...@gmail.com wrote: *const* in C++ is not exactly same as *final* in java. SO unlike java adding the keyword const to a

Re: [algogeeks] Re: output

2011-07-12 Thread rahul
x const a1; x a2; try this. On Tue, Jul 12, 2011 at 11:11 PM, shiv narayan narayan.shiv...@gmail.comwrote: cant i invoke both simultaneously?? if i try to make two objects like x const a; x a; then it gives error..can u explain plz. On Jul 12, 9:55 pm, Sandeep Jain sandeep6...@gmail.com

[algogeeks] Max Arithmetic Subsequence

2011-07-12 Thread Navneet Gupta
I wrote the code as someone gave the reference of the paper where algo to get max arithmetic subsequence was given. For an input of {2,9,4,1,6,7,8,3,10}, i am getting an output of 3, while it should be 5 for {2,4,6,8,10} Below is the implementation, can someone help me understand where am i

[algogeeks] output

2011-07-12 Thread segfault
#includeiostream using namespace std; class x{ int p; public: x(){coutconstructor\n;} x(const x y) { coutcopy constructor\n; } ~x() { cout destructor\n; } void print() { coutprint statement\n; } }; x g() { x b; b.print(); return b; } int main() { x b; x t=g(); }

Re: [algogeeks] Max Arithmetic Subsequence

2011-07-12 Thread sunny agrawal
Algorithm in the paper says works only on sorted arrays it is mentioned in the paper itself On Tue, Jul 12, 2011 at 11:21 PM, Navneet Gupta navneetn...@gmail.comwrote: I wrote the code as someone gave the reference of the paper where algo to get max arithmetic subsequence was given. For an

[algogeeks] output

2011-07-12 Thread segfault
#includeiostream using namespace std; class base { public: virtual void fun() { cout base; } //this is virtual function void run() { fun();} }; class der:public base // base class is inherited { public: void fun() { cout derived; } }; int

[algogeeks] Re: questions related to C

2011-07-12 Thread tendua
regarding question to the generic macro to swap int, float, double # define swap(a,b) ((a)^=(b)^=(a)^=(b)) On Jul 12, 10:08 pm, Aniket Dutta aniketdutt...@gmail.com wrote: c=a+b then find b=c-a; if this b equals previous one then ok else overflow On 7/9/11, John Hayes

[algogeeks] swapping values in C

2011-07-12 Thread tendua
# include stdio.h void swap(int *a, int *b) { *a ^= *b ^= *a ^= *b; } int main() { int a=45, b= 56; // a ^= b ^= a ^= b; swap(a,b); printf(%d %d,a,b); } This code gives output 0, 45 While if we uncomment the line in main

[algogeeks] Re: swapping values in C

2011-07-12 Thread Don
Undefined code can do whatever it wants to. Don On Jul 12, 3:15 pm, tendua 6fae1ce6347...@gmail.com wrote: # include stdio.h void swap(int *a, int *b)         {         *a ^= *b ^= *a ^= *b;         } int main()         {         int a=45, b= 56; //      a ^= b ^= a ^= b;        

[algogeeks] Re: swapping values in C

2011-07-12 Thread Dave
@Tendua: The statement *a ^= *b ^= *a ^= *b violates the sequence point rule, which says that results are undefined if a variable is assigned more than one value between sequence points. Dave On Jul 12, 3:15 pm, tendua 6fae1ce6347...@gmail.com wrote: # include stdio.h void swap(int *a, int

[algogeeks] Re: questions related to C

2011-07-12 Thread Dave
@Tendura: This violates the sequence point rule. Results are undefined. Dave On Jul 12, 2:02 pm, tendua 6fae1ce6347...@gmail.com wrote: regarding question to the generic macro to swap int, float, double # define swap(a,b) ((a)^=(b)^=(a)^=(b)) On Jul 12, 10:08 pm, Aniket Dutta

[algogeeks] Re: swapping values in C

2011-07-12 Thread Don
To make it into valid code, break it into three operations: void swap(int *a, int *b) { *a ^= *b; *b ^= *a; *a ^= *b; } On Jul 12, 3:25 pm, Dave dave_and_da...@juno.com wrote: @Tendua: The statement  *a ^= *b ^= *a ^= *b violates the sequence point

Re: [algogeeks] Re: questions related to C

2011-07-12 Thread hary rathor
#define SWAP(f,type) f(type x, type y)\ {\ type z; z=x, x=y,y=z; \ } swap(M_INT, int) swap(M_FLT,float) swap(m_double,double) int main() { int p =5,q=4; float r=5.4,s=6.9; double v=6.5,w=6.9; swap(p,q); swap(r,s); swap(v,w); } -- You received this message because you are subscribed to the

[algogeeks] Re: questions related to C

2011-07-12 Thread Don
To check for overflow, use condition: if (b (maxuint-a)) return error; Where maxuint is the largest value which can be stored in an unsigned integer. Don On Jul 8, 5:50 am, vikas mehta...@gmail.com wrote: Q1 - write a generic macro to swap two values (int,float,double,pointers as well )

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread saurabh singh
@Navneet This is my version of how delete and strlen must be working.Sorry the presentation is not in correspondence with the style of the group.Apologies for that, *delete[]* Suppose u are a compiler and u see a line like delete[] a,that will mean that Hey the programmer borrowed some memory from

Re: [algogeeks] Reversing the order of words in String

2011-07-12 Thread saurabh singh
And sorry for the late response but my original solution in my previous post doesn't actually required 2 traversals of the complete string. A more clearer algo:- 1.Read original string character by character appending to another string.The string implementation can be that of the std. C++ string.

Re: [algogeeks] microsoft ques

2011-07-12 Thread saurabh singh
Phew I think all cases covered to the best of my knowledge. http://www.ideone.com/xHOQ9 http://www.ideone.com/xHOQ9Few that remain include cases like '\'' \ appear in the source code.can be fixed easily. Also not counting quoted and array initialization {} pairs as depth. Counting the main body as

[algogeeks] Minimum/Maximum Sum path in A Binary Tree

2011-07-12 Thread Rajeev Kumar
I want to find the maximum or minimum sum path in binary tree(*not BST*)? any one have idea? -- Thank You Rajeev Kumar -- 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

  1   2   >