CTDL05 Sortalgorithm
CTDL05 Sortalgorithm
h>
#include <stdlib.h>
int main(){
int n = 10;
int a[10] = {3, 1, 8, 2, 6, 5, 3, 9, 1, 0};
int b[10], c[10], stepsBub = 0, stepsSel = 0, stepsIns = 0;
copy(a, b, n); copy(a, c, n);
//Bubble Sort
bubbleSort(a, n, &stepsBub);
printf("Steps of bubble sort: %d\n", stepsBub);
//Selection Sort
selectionSort(b, n, &stepsSel);
printf("Steps of selection sort: %d\n", stepsSel);
//Insertion Sort
insertionSort(c, n, &stepsIns);
printf("Steps of insertion sort: %d\n", stepsIns);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
srand(time(NULL));
int n = 20;
int a[25], b[25], c[25];
generate(a, n);
printf("Mang ban dau: ");
output(a, n);
copy(a, b, n); copy(a, c, n);
selectionSort(b, n);
output(b, n);
insertionSort(c, n);
output(c, n);
return 0;
}
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main(){
srand(time(NULL));
int n[4] = {10, 20, 50, 100};
int a[105], b[105], c[105], sumStepsBub, sumStepsSel, sumStepsIns;
int stepsBub, stepsSel, stepsIns;