out: Friday, January 8, 2021
due: Monday, January 11, 2021 by 10:00 am.
Write (in C) a function, int CopyAndSort(int8_t*, int8_t*, uint32_t)
, that accepts three arguments:
int8_t
's,
int8_t
's, and
uint32_t
giving the length of each array length
CopyAndSort()
should return 0 if it executes without error
and a positive value if something goes wrong. (A distinct positive return value
is used for each thing that can go wrong so that the caller has some chance
of figuring out what was wrong based on the return value.)
CopyAndSort()
should
copy the elements of the first array into the second array, using insertion
sort as it does so. When done, the second array should contain the elements
of the first array sorted in non-decreasing order.
Your code should insert the array elements in the proper place one at a
time as they are copied.
Don't copy the entire array first and then sort it.
(Don't use any library implementation of sort.)
When printing array values you should use
the printf
format specifier for int8_t
, rather than using a more
common specifier (like %d
) that would require a conversion of the array element
from int8_t
to some other type.
If you think it's a good idea, you can implement additional
helper functions to be used by CopyAndSort()
,
but that isn't required.
All functions should reside in the single ex01.c
file.
Do a $ git pull
to fetch ex01 starter code
consisting of files ex01.c
and ex01.h
.
You should complete the implementation in ex01.c
and modify ex01.h
so that when the program is built
and runs it sorts the following array:
{3, 2, -5, 7, 17, 6, 1, 7, 8, -8, 6}The final code should behave like this:
bash$ clint.py ex01.c Done processing ex01.c Total errors found: 0 bash$ gcc -Wall -g -std=c17 -o ex01 ex01.c bash$ ./ex01 -8 -5 1 2 3 6 6 7 7 8 17 bash$
Your code must:
ex01.c
and ex01.h
You should submit your ex01.c
and ex01.h
files using the Gradescope dropbox linked on the
course resources web page.
(You should have received an email message from Gradescope with your login information. Your userid is your @uw.edu email address. If your gradescope account is not set up properly, please send email to the cse333-staff[at]cs address with your uw netid so we can fix the problem.)