Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SortingAlgorithm.cpp : This file contains the 'main' function. Program execution begins and ends there.
- #include <iostream>
- void swapByValue(int el1, int el2)
- {
- // Swapping algorithm
- int temp = el1;
- el1 = el2;
- el2 = temp;
- /*std::cout << "el1: " << el1 << "\n\n";
- std::cout << "el2: " << el2 << "\n\n";*/
- }
- void swapByReference(int& el1, int& el2)
- {
- int temp = el1;
- el1 = el2;
- el2 = temp;
- }
- int main()
- {
- int num1 = 5;
- int num2 = 6;
- // Before swapping
- std::cout << "Before Swap\n";
- std::cout << "num1: " << num1 << "\n";
- std::cout << "num2: " << num2 << "\n\n\n";
- // After swapping
- std::cout << "After Swap\n";
- // call function here
- // swapByValue(num1, num2);
- swapByReference(num1, num2);
- std::cout << "num1: " << num1 << "\n";
- std::cout << "num2: " << num2 << "\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement