Sorting
Sorting
#include <iostream>
using namespace std;
int main() {
int arraySize = 7;
int A[7] = {38, 27, 43, 3, 9, 82, 10};
int low = 0;
int high = arraySize - 1;
return 0;
}
Quick sort
#include <iostream>
using namespace std;
// Partition function divides the array and returns the pivot index
int Partition(int A[], int low, int high) {
int pivot = A[low]; // Choose the first element as the pivot
int leftwall = low; // The "wall" separates elements smaller than
pivot
// Put the pivot in its correct position (middle of the smaller and larger
elements)
swap(A[low], A[leftwall]);
return 0;
}
Bubble Sort
#include <iostream>
using namespace std;
int main() {
int a[10];
int k;
bubbleSort(a, n);
return 0;
}
Insertion Sort
#include <iostream>
using namespace std;
int main() {
int A[] = {8, 3, 5, 2};
int n = sizeof(A) / sizeof(A[0]);
insertionSort(A, n);
return 0;
}
SelectionSort
#include <iostream>
using namespace std;
int main() {
int A[] = {8, 3, 5, 2};
int n = sizeof(A) / sizeof(A[0]);
selectionSort(A, n);
return 0;
}