Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- int calc_sum(int a, int b) {
- return a + b;
- }
- void pointer_teory() {
- int boburbek = 16;
- cout << &boburbek << endl;
- auto pBoburbek = &boburbek;
- cout << pBoburbek << " " << *pBoburbek << endl;
- int *pB2 = &boburbek;
- cout << *(&boburbek) << endl;
- cout << &(*pBoburbek) << endl;
- double PI_val = 3.1415;
- double* pPI_val = &PI_val;
- cout << pPI_val << " " << *pPI_val << endl;
- cout << &PI_val << " " << PI_val << endl;
- int a = 5, b = 7, c = 13;
- int *pa = &a, *pb = &b, *pc = &c;
- *pc = *pa + *pb;
- cout << "C: " << c << endl;
- }
- void my_swap2(int* pa, int* pb) {
- cout << "IN FUN: " << *pa << *pb << endl;
- int tmp = *pb;
- *pb = *pa;
- *pa = tmp;
- cout << "IN FUN: " << *pa << *pb << endl;
- }
- void my_swap(int& a, int& b) {
- //cout << "IN FUN: " << a << b << endl;
- int tmp = b;
- b = a;
- a = tmp;
- //cout << "IN FUN: " << a << b << endl;
- }
- void test_swap() {
- int a = 5, b = 7, c = 9, d = 11;
- cout << a << " " << b << " "
- << c << " " << d << endl;
- my_swap(a, b);
- //swap(a, b);
- // do it
- // case 1 (Memory)
- //int tmp = b;
- //b = a;
- //a = tmp;
- //tmp = d;
- //d = c;
- //c = tmp;
- // case 2 (Operation)
- //a = a + b;
- //b = a - b;
- //a = a - b;
- cout << a << " " << b << " "
- << c << " " << d << endl;
- //pointer_teory();
- }
- void show_arr(int size, int arr[]) {
- for (int k = 0; k < size; k++)
- cout << arr[k] << " ";
- cout << endl;
- }
- void shafle() {
- int arr[]{ 1,2,3,4,5 };
- show_arr(5, arr);
- for (int m = 0; m < 5; m++) {
- int k = rand() % 5;
- int n = rand() % 5;
- my_swap(arr[k], arr[n]);
- }
- show_arr(5, arr);
- //cout << k << " " << n << endl;
- }
- int main() {
- srand(time(NULL));
- shafle();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement