Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- void swapnumbers (int &, int &);
- void bubblesort (int arr[], int n)
- {
- int i, j;
- for(i=n-1; i>0; i--)
- {
- for (j=0; j<i;j++)
- {
- if (arr[j] > arr[j+1])
- {
- int temp= arr[j+1];
- arr[j+1]=arr[j];
- arr[j]=temp;
- }
- }
- }
- }
- void swapnumbers (int &A, int &B)
- {
- int temp = B;
- B = A;
- A = temp;
- }
- void swapval (int x, int y)
- {
- int temp = y;
- y = x;
- x = temp;
- return;
- }
- int main()
- {
- cout<<"Bubble Sort\n";
- int array[20]= {1,2,5,6,3,7,6,8,9,3,6,4,7,3,7,5,4,8,5,9};
- int size = 20;
- bubblesort(array, size);
- for (int i = 0; i<20; i++)
- {
- cout<<array[i]<<" ";
- }
- cout<<"\n";
- cout<<"\n";
- cout<<"Call by Reference to Swap to Values\n";
- int a = 10;
- int b = 5;
- cout<<"Before Swap "<<a<<" "<<b;
- cout<<"\n";
- swapnumbers (a,b);
- cout<<"After Swap "<<a<<" "<<b;
- cout<<"\n";
- cout<<"\n";
- cout<<"Call by Value to Swap but not actually Swap\n";
- int x = 20;
- int y = 10;
- cout<<"Before Swap "<<x<<" "<<y;
- cout<<"\n";
- swapnumbers (a,b);
- cout<<"After Swap "<<x<<" "<<y;
- cout<<"\n";
- cout<<"\n";
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement