Untitled

mail@pastecode.io avatar
unknown
plain_text
3 years ago
966 B
0
Indexable
Never
#include <stdio.h>
#include <stdlib.h>

void bubbleSort(int a[], int size_a);

int main(void)
{
    /// Q1a
    printf("Q1a\n\n");
    int stu_id = 70357003;

    int arr[] = {28, 10, 12, 88, 41, 33, 21, 102, 99, 72};
    int arr_size = sizeof(arr)/sizeof(arr[0]);

    printf("Array before bubble sort: { ");
    for(int n = 0; n < arr_size; n++){
        printf("%d ", arr[n]);
    }
    printf("}\n");

    bubbleSort(arr, arr_size);

    printf("\n\nStudent ID: %d\n\n", stu_id);
    return 0;
}

void bubbleSort(int a[], int size_a){
    int i, j, temp;

    for(i = 0; i < size_a; i++){
        for(j = 0; j < size_a - 1 - i; j++){
            if(a[j] > a[j+1]){
                temp = a[j];
                a[j] = a[j+1];
                a[j+1] = temp;
            }
        }
    }

    printf("Array after bubble sort: { ");
    for(i = 0; i < size_a; i++){
        printf("%d ", a[i]);
    }
    printf("}");

}