blog/pb071/bonuses/03.md
Matej Focko f801e4bb16
chore: add ‹last_update› to docs-like posts
Allow showing ‹last updated› on the pages and also rename the files
where necessary, so they are shown in the order they were created.

Signed-off-by: Matej Focko <mfocko@redhat.com>
2023-08-15 17:27:16 +02:00

3.3 KiB

id title description last_update
seminar-03 3rd seminar Select sort implementation on arrays.
date
2023-03-07

:::caution

Deadline for the submission of the bonus is March 16th 24:00.

:::

:::tip

In case you have any questions, feel free to reach out either by email, Discord or just by submitting an issue here.

:::

This assignment has two versions. For the light version you can get 1.5 K₡. For the full fat 3 K₡. You can choose only one of them.

To both of them you are given some basic tests. You can also have a look at the code used by the tests and use it to your advantage.

Details can be found in the doxygen comments included in the source files.

Light version (main_light.c)

Source

For the light version you have 3 functions to finish:

  1. swap - that swaps two ints passed by pointers.
  2. maximum - that returns index of the biggest int in the array.
  3. select_sort - that sorts passed array using Select Sort.

Full fat version (main.c)

Source

For the full fat version you have 4 functions to implement:

  1. swap - that swaps two variables passed by pointers.
  2. maximum - that returns index of the biggest element in the array using the comparator.
  3. select_sort - that sorts passed array using Select Sort.
  4. int_comparator - that is used for generic sort and maximum

To 2nd and 3rd function you are given a pseudocode that you can use to implement it.

:::tip Function pointers

In the skeleton of the “full fat” version you might have noticed a weird type signature of both the maximum and select_sort functions. Those functions get passed a function pointer to the comparator that you use for comparing the respective elements in the passed in array.

If we take the parameter from one of the functions from the skeleton:

int (*comp)(const void *, const void *)

comp is a function pointer to a function that takes two pointers of unspecified type, i.e. pure address to the memory (you don't know what stored in there), and returns an int.

You can pass the function by simply using its name. (There is no need to use & to get its address.) And you can also call the function by “calling” the function pointer, e.g. comp(left, right).

:::

Submitting

For submitting the bonus assignment you can follow the same procedure as for submitting the homeworks, that is:

  1. On branch main add the provided skeleton.
  2. Checkout new branch seminar-bonus-03.
  3. Add your solution to the newly created branch.
  4. Create a MR to the main branch with me (@xfocko) as the reviewer.

:::tip Directory structure for bonuses

Ideally create a directory seminar-bonuses in the root of your repository with bonuses in their own subdirectories.

Structure of your repository can look like this:

.
├── bonuses
│   └── seminar-03
├── hello
├── hw01
├── hw02
├── seminar-01
├── seminar-02
└── seminar-03

or

.
├── bonus-seminar-03
├── hello
├── hw01
├── hw02
├── seminar-01
├── seminar-02
└── seminar-03

Structure of the bonuses is entirely up to you, just keep it consistent.

:::