Skip to content
Snippets Groups Projects
T2.c 867 B
Newer Older
antux18's avatar
antux18 committed
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <pthread.h>

#define SIZE 10000

void swap(int *xp, int *yp);
void sort(int arr[], int size);

// Function prototypes for thread tasks
// TODO: Declare functions for calculating mean and median

int main() {
    int arr[SIZE];
    for(int i = SIZE - 1; i >= 0; i--)
        arr[(SIZE - 1) - i] = i % 2;

    // TODO: Implement your solution here
    // TODO: Create threads for calculating mean and median
    // TODO: Display the result (mean, median)
    // TODO: Print TIDs of involved threads

    return 0;
}

void swap(int *xp, int *yp) {
    int temp = *xp;
    *xp = *yp;
    *yp = temp;
}

void sort(int *arr, int size) {
    for (int i = 0; i < size - 1; i++)
        for (int j = 0; j < size - i - 1; j++)
            if (arr[j] > arr[j + 1])
                swap(&arr[j], &arr[j + 1]);
}