From 9917cd31f010b404d373bce01ac5298343523c3f Mon Sep 17 00:00:00 2001 From: surtur Date: Sun, 12 Apr 2020 23:43:35 +0200 Subject: [PATCH] updated .drone.yml + added some files + changes * added bubblesort func * targeting latest cdev image now * a couple more changes (I know it's lame) --- .drone.yml | 6 +++--- CMakeLists.txt | 2 +- bubblesort.c | 38 ++++++++++++++++++++++++++++++++++++++ bubblesort.h | 10 ++++++++++ main.c | 14 +++++++++----- minmax.c | 12 ++++-------- 6 files changed, 65 insertions(+), 17 deletions(-) create mode 100644 bubblesort.c create mode 100644 bubblesort.h diff --git a/.drone.yml b/.drone.yml index acd2842..2b65a13 100644 --- a/.drone.yml +++ b/.drone.yml @@ -8,7 +8,7 @@ platform: steps: - name: build pull: always - image: immawanderer/archlinux-cdev + image: immawanderer/archlinux-cdev:latest commands: - cmake CMakeLists.txt - make @@ -44,7 +44,7 @@ steps: pull: always image: appleboy/drone-discord:1.2.4 settings: - message: "{{#success build.status}} ✅ [Build #{{build.number}}]({{build.link}}) of `{{repo.name}}` succeeded.\nevent: **`{{build.event}}`**\ncommit [`${DRONE_COMMIT_SHA:0:7}`](https://git.dotya.ml/${DRONE_REPO}/commit/${DRONE_COMMIT_SHA}) by {{commit.author}} on `{{commit.branch}}`\n```{{commit.message}}``` {{else}} ❌ [Build #{{build.number}}]({{build.link}}) of `{{repo.name}}` failed.\nevent: **`${DRONE_BUILD_EVENT}`**\ncommit [`${DRONE_COMMIT_SHA:0:7}`](https://git.dotya.ml/${DRONE_REPO}/commit/${DRONE_COMMIT_SHA}) by {{commit.author}} on `{{commit.branch}} on `{{commit.branch}}`:\n``` {{commit.message}} ``` {{/success}}\n\n" + message: "{{#success build.status}} ✅ [Build #{{build.number}}]({{build.link}}) of `{{repo.name}}` succeeded.\nevent: **`{{build.event}}`**\ncommit [`${DRONE_COMMIT_SHA:0:7}`](https://git.dotya.ml/${DRONE_REPO}/commit/${DRONE_COMMIT_SHA}) by {{commit.author}} on `{{commit.branch}}`{{else}} ❌ [Build #{{build.number}}]({{build.link}}) of `{{repo.name}}` failed.\nevent: **`${DRONE_BUILD_EVENT}`**\ncommit [`${DRONE_COMMIT_SHA:0:7}`](https://git.dotya.ml/${DRONE_REPO}/commit/${DRONE_COMMIT_SHA}) by {{commit.author}} on `{{commit.branch}} on `{{commit.branch}}`{{/success}}" webhook_id: from_secret: discord_webhook_id webhook_token: @@ -80,7 +80,7 @@ steps: pull: always image: appleboy/drone-discord:1.2.4 settings: - message: "{{#success build.status}} ✅ [Hourly build #{{build.number}}]({{build.link}}) of `{{repo.name}}` succeeded.\nevent: **`{{build.event}}`**\ncommit [`${DRONE_COMMIT_SHA:0:7}`](https://git.dotya.ml/${DRONE_REPO}/commit/${DRONE_COMMIT_SHA}) by {{commit.author}} on `{{commit.branch}}`\n```{{commit.message}}``` {{else}} ❌ [Hourly build #{{build.number}}]({{build.link}}) of `{{repo.name}}` failed.\nevent: **`${DRONE_BUILD_EVENT}`**\ncommit [`${DRONE_COMMIT_SHA:0:7}`](https://git.dotya.ml/${DRONE_REPO}/commit/${DRONE_COMMIT_SHA}) by {{commit.author}} on `{{commit.branch}} on `{{commit.branch}}`:\n``` {{commit.message}} ``` {{/success}}\n\n" + message: "{{#success build.status}} ✅ [Hourly build #{{build.number}}]({{build.link}}) of `{{repo.name}}` succeeded.\nevent: **`{{build.event}}`**\ncommit [`${DRONE_COMMIT_SHA:0:7}`](https://git.dotya.ml/${DRONE_REPO}/commit/${DRONE_COMMIT_SHA}) by {{commit.author}} on `{{commit.branch}}` {{else}} ❌ [Hourly build #{{build.number}}]({{build.link}}) of `{{repo.name}}` failed.\nevent: **`${DRONE_BUILD_EVENT}`**\ncommit [`${DRONE_COMMIT_SHA:0:7}`](https://git.dotya.ml/${DRONE_REPO}/commit/${DRONE_COMMIT_SHA}) by {{commit.author}} on `{{commit.branch}} on `{{commit.branch}}`{{/success}}" webhook_id: from_secret: discord_webhook_hourly_id webhook_token: diff --git a/CMakeLists.txt b/CMakeLists.txt index 4fd2c95..ce8232e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,4 +2,4 @@ cmake_minimum_required(VERSION 3.5) project(pjc-0x03 LANGUAGES C) -add_executable(pjc-0x03 main.c minmax.c minmax.h main.h) +add_executable(pjc-0x03 main.c minmax.c minmax.h main.h bubblesort.c bubblesort.h) diff --git a/bubblesort.c b/bubblesort.c new file mode 100644 index 0000000..d0bfc85 --- /dev/null +++ b/bubblesort.c @@ -0,0 +1,38 @@ +#include "bubblesort.h" + +void bubblesort(int a[], int elems){ + int a_length = sizeof(a)/sizeof(char); + int no_more_cycles = 0; + + printf("[i] a_length = %d\n", a_length); + + printf("[*] array [%d]:\n", a_length); + for (int j = 0; j < a_length; ++j) { + printf("%d ", a[j]); + } + printf("\n"); + + while (no_more_cycles != a_length) { + no_more_cycles = 0; + for (int i = 0; i < a_length; ++i) { + if (a[i] > a[i+1]){ + int tmp = a[i]; + a[i] = a[i+1]; + a[i+1] = tmp; + } + else { + no_more_cycles++; + } + } + } + + printf("[*] bubblesorted array [%d]:\n", a_length); + for (int i = 0; i < a_length; ++i) { + printf("%d ", a[i]); + } + printf("\n"); +} + +int return_bubblesorted(int a[]){ + return 0; +} diff --git a/bubblesort.h b/bubblesort.h new file mode 100644 index 0000000..a0409dc --- /dev/null +++ b/bubblesort.h @@ -0,0 +1,10 @@ +#ifndef PJC_0X03_BUBBLESORT_H +#define PJC_0X03_BUBBLESORT_H + +#include + +void bubblesort(int a[], int elems); + +int return_bubblesorted(int a[]); + +#endif //PJC_0X03_BUBBLESORT_H diff --git a/main.c b/main.c index 123f656..3401a1c 100644 --- a/main.c +++ b/main.c @@ -2,6 +2,7 @@ #include #include "main.h" #include "minmax.h" +#include "bubblesort.h" int get_userguess(){ int x = -1; @@ -18,7 +19,8 @@ int get_userguess(){ while (fgetc(stdin) != '\n'){ } printf("[*] give me a correct value\n"); - printf("[*] stop gibbering around\n my guess >>> "); + break; +// printf("[*] stop gibbering around\n my guess >>> "); } } return x; @@ -31,14 +33,15 @@ int lemmego(){ int main() { - int selection, max, min = 0; + int selection, max, min; + int a[] = {1,2,3,5,4,0}; while ( selection != 8 ) { printf("\npick a choice\n"); printf("1 - max\n" "2 - min\n" - "3 - nothing..\n" - "4 - here yet\n" + "3 - bubblesort\n" + "4 - nothing here yet\n" "8 - quit\n" ">> "); @@ -54,6 +57,7 @@ int main() printf("minumum je %d\n", min); break; case 3: + bubblesort(a,6); break; case 4: break; @@ -61,7 +65,7 @@ int main() lemmego(); return 9000; default: - printf("invalid option\n"); + printf("[*] invalid option\n"); selection = 0; break; } diff --git a/minmax.c b/minmax.c index dd15b60..575e98d 100644 --- a/minmax.c +++ b/minmax.c @@ -5,8 +5,8 @@ int maximum() { int x, y, z; - printf("Zadejte 3 cisla oddelena mezerou: "); printf("** printmax **\n"); + printf("Zadejte 3 cisla oddelena mezerou: "); scanf("%d%d%d", &x, &y, &z); int max = x; @@ -16,8 +16,6 @@ int maximum() if ( z > max ) { max = z; } - // pokud je y vetsi, ulozime jej do max - // pokud je z vetsi, ulozime jej do max return max; } @@ -25,20 +23,18 @@ int minimum() { int selection, max, min = 0; - while ( selection != 8 ) { + int x, y, z; - printf("Zadejte 3 cisla oddelena mezerou: "); printf("** printmin **\n"); + printf("Zadejte 3 cisla oddelena mezerou: "); scanf("%d%d%d", &x, &y, &z); - int min = x; - + min = x; if ( y < min ) { min = y; } if ( z < min ) { min = z; } - } return min; } \ No newline at end of file