Skip to content

Instantly share code, notes, and snippets.

@saifsmailbox98
Created December 27, 2018 18:21
Show Gist options
  • Save saifsmailbox98/b67d819f9c18f06403f8bf5da32da36a to your computer and use it in GitHub Desktop.
Save saifsmailbox98/b67d819f9c18f06403f8bf5da32da36a to your computer and use it in GitHub Desktop.
void swap(int&a, int&b) {
int temp;
temp = a;
a = b;
b = temp;
}
void display(int a[], int n) {
for (int i = 0; i < n; i++)
printf("%d ", a[i]);
printf("\n");
}
void bubble_sort(int A[], int n){
for(int k=0; k<n-1; k++){
for(int i=0; i<n-k-1; i++){
if(A[i]>A[i+1]){
swap(A[i], A[i+1]);
}
}
}
}
void selection_sort(int A[], int n) {
int min;
for(int i=0; i<n-1; i++){
min = i;
for(int j=i+1; j<n; j++){
if(A[j]<A[min]){
min = j;
}
}
swap(A[min], A[i]);
}
}
void insertion_sort(int A[], int n)
{
for(int i=0; i<n; i++){
int temp = A[i];
int j = i;
while(j>0&&temp<A[j-1]){
A[j] = A[j-1];
j--;
}
A[j] = temp;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment