OS_assig_1_TIA19
OS_assig_1_TIA19
OS_assig_1_TIA19
int main() {
int arr[] = {47, 32, 21, 17, 14};
int n = sizeof(arr)/sizeof(arr[0]);
int status;
pid_t pid;
switch(i) {
case 1: // Bubble Sort
printf("Child %d performing Bubble Sort...\n", i);
bubbleSort(childArr, n);
printf("Sorted array by Bubble Sort: ");
printArray(childArr, n);
exit(0);
break;
case 2: // Quicksort
printf("Child %d performing Quicksort...\n", i);
quickSort(childArr, 0, n-1);
printf("Sorted array by Quicksort: ");
printArray(childArr, n);
exit(0);
break;
// Bubble Sort
void bubbleSort(int arr[], int n) {
int i, j;
for (i = 0; i < n-1; i++) {
for (j = 0; j < n-i-1; j++) {
if (arr[j] > arr[j+1]) {
int temp = arr[j];
arr[j] = arr[j+1];
arr[j+1] = temp;
}
}
}
}
// Quicksort
void quickSort(int arr[], int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
// Merge Sort
void mergeSort(int arr[], int l, int r) {
if (l < r) {
int m = l + (r - l) / 2;
mergeSort(arr, l, m);
mergeSort(arr, m + 1, r);
merge(arr, l, m, r);
}
}
int i = 0, j = 0, k = l;