#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;
#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;
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
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
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
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
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
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;
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);
}
@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
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';
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
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
@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
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
@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
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
@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
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
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
@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
@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
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
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,
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
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;
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;
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
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
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
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== '{' )
{
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
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
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,
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
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
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
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
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
@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
@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
@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 !!
@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,
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
@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
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
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.
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
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
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
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
@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
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);
}
@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
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
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,
@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
@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
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
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-
@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
@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
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
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
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
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
@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
@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
#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
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() {
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
// 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,
@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
*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
@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
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
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
@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
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
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
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
@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
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
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
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
#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();
}
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
#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
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
# 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
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;
@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
@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
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
#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
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 )
@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
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.
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
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 - 100 of 131 matches
Mail list logo