/**
* Copyright (c) 2022 Raspberry Pi (Trading) Ltd.
*
* SPDX-License-Identifier: BSD-3-Clause
*/
#include "pico/stdlib.h"
#include "pico/cyw43_arch.h"
#include <stdio.h>
#include <time.h>
#define SIZE 5000
void swap(int* a, int* b) {
int t = *a;
*a = *b;
*b = t;
}
int partition(int arr[], int low, int high) {
int pivot = arr[high];
int i = (low - 1);
for (int j = low; j <= high - 1; j++) {
if (arr[j] < pivot) {
i++;
swap(&arr[i], &arr[j]);
}
}
swap(&arr[i + 1], &arr[high]);
return (i + 1);
}
void quickSort(int arr[], int low, int high) {
if (low < high) {
int pi = partition(arr, low, high);
quickSort(arr, low, pi - 1);
quickSort(arr, pi + 1, high);
}
}
int main() {
int arr[SIZE];
stdio_init_all();
if (cyw43_arch_init()) {
printf("Wi-Fi init failed");
return -1;
}
// Initialize random seed
srand(time(NULL));
// Fill array with random values
for (int i = 0; i < 8000; i++) {
arr[i] = rand() % 10000; // Random values between 0 and 9999
}
printf("Array initialized with random values.\n");
// Sort the array
quickSort(arr, 0, SIZE - 1);
printf("Array sorted using quicksort.\n");
// Print first 10 and last 10 elements to verify sorting
printf("First 10 elements: ");
for (int i = 0; i < 10; i++) {
printf("%d ", arr[i]);
}
while (true) {
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 1);
printf("LED ON\n");
sleep_ms(444);
cyw43_arch_gpio_put(CYW43_WL_GPIO_LED_PIN, 0);
printf("LED OFF\n");
sleep_ms(444);
}
}