由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
Programming版 - 做题了,做题了,看谁能搞清楚
相关主题
请教register问几个神经网络的问题
C++ software engineer 3 years expectation变量就是个酱油瓶子
C++ Q87: What is wrong with this swap function? (转载)来,做题吧。
请教算法题大家来做题C++。
reverse bits 的题目问一下学习C,做题的资源。。。
靠,被一个CRC32搞了半天。做题了做题了,集合分组问题
问个C++算法强迫症爱好者进来做题了
请教个bitarray distance的问题面试要求上机做题的,你们去不去面?
相关话题的讨论汇总
话题: explain话题: swap话题: correct话题: int话题: 做题
进入Programming版参与讨论
1 (共1页)
d*******n
发帖数: 369
1
swap a and b using XOR (no the third variable). The following function is
correct? Explain
swap(int *a, int *b)
{
*a ^= *b ^= *a ^= *b;
}
I found that if I write it as follows, it's correct
*a ^= *b;
*b ^= *a;
*a ^= *b;
but *a ^= *b ^= *a ^= *b is wrong but why? explain in detail
t****t
发帖数: 6806
2
peng u to death
http://c-faq.com/expr/xorswapexpr.html

【在 d*******n 的大作中提到】
: swap a and b using XOR (no the third variable). The following function is
: correct? Explain
: swap(int *a, int *b)
: {
: *a ^= *b ^= *a ^= *b;
: }
: I found that if I write it as follows, it's correct
: *a ^= *b;
: *b ^= *a;
: *a ^= *b;

a****l
发帖数: 8211
3
这种东西有什么用处?你调用都是有开销的,与其浪费在这些东西上还不如直接用一个中
间变量做个简单的替换.最简单的说,你现在搞个*a,*b这就是至少两个int,还没算别的
出入堆的东西.

【在 d*******n 的大作中提到】
: swap a and b using XOR (no the third variable). The following function is
: correct? Explain
: swap(int *a, int *b)
: {
: *a ^= *b ^= *a ^= *b;
: }
: I found that if I write it as follows, it's correct
: *a ^= *b;
: *b ^= *a;
: *a ^= *b;

N***m
发帖数: 4460
4
想起当年朗道嘲笑哥德巴赫猜想:难道素数不是用来相乘的吗?

【在 a****l 的大作中提到】
: 这种东西有什么用处?你调用都是有开销的,与其浪费在这些东西上还不如直接用一个中
: 间变量做个简单的替换.最简单的说,你现在搞个*a,*b这就是至少两个int,还没算别的
: 出入堆的东西.

z****e
发帖数: 2024
5
茴香豆的“茴”字的写法啊。
1 (共1页)
进入Programming版参与讨论
相关主题
面试要求上机做题的,你们去不去面?reverse bits 的题目
到哪搞清楚点的design patterns UML diagrams?靠,被一个CRC32搞了半天。
搞清楚什么叫做底层先问个C++算法
What is the methology to solve problems like swapping variables?请教个bitarray distance的问题
请教register问几个神经网络的问题
C++ software engineer 3 years expectation变量就是个酱油瓶子
C++ Q87: What is wrong with this swap function? (转载)来,做题吧。
请教算法题大家来做题C++。
相关话题的讨论汇总
话题: explain话题: swap话题: correct话题: int话题: 做题