
doanmac
Tinh x^n
int power(int x , int n) {
int tmp = 1;
if (n>0) {
tmp = power(x, n/2)
if (n%2)
tmp = tmp*tmp;
else
tmp = tmp*tmp*x;
}
Return tmp;
}
Sap xep
Insertion sort
Void insertsort(int a[], int n )
Int i , j , last ;
For (i = 2; i < n ; i++) {
Last = a[i];
J = I;
While((j>1)&&(a[j-1]>last)){
A[j] = a[j-1];
J = j -1 ;}
A[j] = last;
}
}
Sap xep lua tron selection sort
Void seclectionsort(int a[], n) {
Int I,j, min, temp;
For ( I = 0 ; I < n-1 ; i++) {
Min = I;
For (j = i+1; j<n;j++) {
If (a[j] < a[min]) min = j;
}
Swap(a[i],a[j]);
}
}
Sap xep noi bot (bubble sort)
Void bubblesort(int a[], int n)
Int I , j
For (I = n-1 ; i>= 0 ; i--){
For(j = 1; j<=I; j++){
If (a[j-1] >a[j])
Swap(a[j-1],a[j]);
}
}
}
Bạn đang đọc truyện trên: Truyen247.Pro