Algorithms Chapter 2
@ Mr. Eric | Tuesday, Aug 24, 2021 | 2 minute read | Update at Friday, Aug 20, 2021

This time the video is about selection sort. I’m fine with arrays and linked lists so far(I think I’m goin to use it in the future) and with selection sort, too, just bubble sort and selection sort are so similar. By the way, I need to say that I’m enjoying this book really much and until now, it has been my favorite book about anything that has to do with knowledge. It seems like I get to know more things from nowhere while reading a comic book. The pictures are nice!

Algorithms are fun, too, but philosophy is also fun with “An outline of philosophy” by Russell! I have a new “Brilliant idea” to make a much cooler siries of video… About philosophy! I’ll like to share what I had read with other people, and trust me… This book isn’t a comic book, but just as much fun! Russell has been satirizing people, not using one rude word. And the chapters all have meaningful titles that will “grab” you right into it!

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# include <stdio.h>
# include <stdlib.h>
# include <limits.h>

# define SIZE 6

int find_smallest(int *array)
{
    int smallest = array[0];
    int smallest_index = 0;
    for (int i = 1; i < SIZE; i++)
    {
        if (array[i] < smallest)
        {
            smallest = array[i];
            smallest_index = i;
        }
    }
    return smallest_index;
}

int find_largest(int *array)
{
    int largest = array[0];
    int largest_index = 0;
    for (int i = 1; i < SIZE; ++i)
    {
        if (array[i] > largest)
        {
            largest = array[i];
            largest_index = i;
        }
    }
    return largest_index;
}

int *selection_sort(int *array)
{
    int *newArray = (int *)malloc(SIZE * sizeof(int));
    for (int i = 0; i < SIZE; i++)
    {
        //int smallest = find_smallest(array);
        int largest = find_largest(array);
        //newArray[i] = array[smallest];
        newArray[i] = array[largest];
        //array[smallest] = INT_MAX;
        array[largest] = INT_MIN;
    }
    return newArray;
}

int main(void)
{
    int array[SIZE] = {9, 18, 4, 7, 2, 20};
    int *sarray = selection_sort(array);
    for (int i = 0; i < SIZE; i++)
    {
        printf("%d\n", sarray[i]);
    }
    return 0;
}
Mr. Eric
Life writes the best stories. Let’s study together! Never copy please!
A Friendly Introduction to Number Theory Algebra Ii Algebra Problem Algorithm Code Euclid Geometry Germination Method Number Theory Opinion Poetry Appreciation Reflection Seed Solve Speech Stop Motion

© 2020 - 2023 Mr. Eric

Powered by Hugo with theme Dream.

Mr. Eric

I am a student, learn, happy.

Always happy.