I am trying to find out using the below code with sort an array in asscending order. And I find method 1,2,3,4 all get the same result:1234.
Which method is the best?
And when and why should should I use pointer /reference? Thanks you.
Using & to call, and * in function parameter
Just used * in function parameter
Just used & in function parameter
nothing:
#include <iostream> using namespace std; void swap(int a,int b){ int t; t=a; a=b; b=t; } void main(){ int a[]={1,2,3,4}; for (int i=1; i<3; i++) for (int j=3; j>i;j--) if(a[j]<a[j-1]) swap(a[j],a[j-1]); cout << a[0] <<a[1]<<a[2]<<a[3]; }