Design & Analysis of Algorithms: Assignment # 03
Design & Analysis of Algorithms: Assignment # 03
Total Marks: 04
Obtained
Marks:
Instructions: Copied or shown assignments will be marked zero. Late submissions are not
entertained in any case.
Question
Write a C/C++ program that implements the Quicksort algorithm using the Lomuto
partition scheme to sort an array of integers in descending order.
CODE:
#include <iostream>
#include <limits>
// Partition process
for (int j = low; j < high; j++) {
if (arr[j] < pivot) { // For ascending order
i++;
// Swap arr[i] and arr[j]
int temp = arr[i];
arr[i] = arr[j];
arr[j] = temp;
}
}
int main() {
int n;
int *arr = new int[n]; // Dynamic array allocation for C++98 compatibility
// Apply Quicksort
quicksort(arr, 0, n - 1);
return 0;
}
Output: