CSE 333 24su Exercise 1

Due: Monday, June 24th, 2024 by 10:00 am; No late exercises accepted.
Goals: Implement and use a function with array parameters; process and print fixed-width integer data

Description: Write (in C) a function CopyAndSort that accepts two arrays of int64_t's and an array length as arguments. You should assume the lengths of the two arrays are the same. The function should iterate through the elements of the first array and use insertion sort to store them into the second array in non-decreasing (i.e., ascending, but there might be duplicates) sorted order. Your code should insert the array elements in the proper place one at a time as they are copied. Do not copy the entire array first and then sort it.

You should assume that the array lengths and subscripts can be stored in variables and passed as parameters of type int. When printing array values you should use the correct format for int64_t values rather than printf codes for built-in C types like int, short, or long (Hint: explore the stdint.h and inttypes.h libraries). You should decompose the problem into multiple functions if appropriate.

(Note about int: in systems code we very often will prefer to use types like int32_t with precisely known sizes, but we also want to follow the Google style guide, which says that if all you need is an int, you should use int. See the Google C++ style guide for more details. The information in there that is not C++-specific also applies to our C code. For this exercise we'll use arrays whose elements have explicitly-sized integer elements, but the array sizes and indices are ordinary integer values.)

Write a main() function that exercises your CopyAndSort function. When your program runs, it should sort the following array and print out the results:

     {3, 2, -5, 7, 17, 42, 6, 333, 7, 8, -8, 6}
When your program compiles and runs, we should see:
    bash$ gcc -Wall -g -std=c17 -o ex1 ex1.c
    bash$ ./ex1
    -8 -5 2 3 6 6 7 7 8 17 42 333
    bash$


As usual, your code must:

You should submit your exercise to the course Gradescope.