noswap.cpp
来自「这是数据结构、算法与应用-C++语言描述的代码」· C++ 代码 · 共 31 行
CPP
31 行
// incorrect swap method
#include<iostream>
using namespace std;
void swap(int x, int y)
{// swap the integers x and y
int temp = x;
x = y;
y = temp;
}
// test the swap function
int main()
{
int a = 2;
int b = 3;
// output the values
cout << "Before swapping, a = " << a << " b = " << b << endl;
// swap a and b
swap(a,b);
// output the new values
cout << "After swapping, a = " << a << " b = " << b << endl;
return 0;
}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?