嵌入式軟件工程師C語言經典筆試2
阿新 • • 發佈:2019-03-16
onclick define 中間 bee 字符 swap 軟件工程師 spa 鏈表的反轉
1. 使用宏定義swap函數,不使用中間變量
#define swap(x,y) {(x) = (x) + (y);(y) = (x) - (y);(x) = (x) - (y)}
View Code
2. 實現字符串的反轉
#define swap(x,y) {(x) = (x) + (y);(y) = (x) - (y);(x) = (x) - (y);} void reverse(char *string) { int len = strlen(string); char *begin = string; char *end = stringView Code+ len - 1; while (begin < end) { swap(*begin,*end); begin++; end--; } }
3. 實現單鏈表的反轉
4. 計算二叉樹的高度
5. 判斷一個數是否是2的次冪
inline Is2exp(int i) { return (i&(i-1))?0:1); }View Code
嵌入式軟件工程師C語言經典筆試2