Created
May 12, 2024 13:11
-
-
Save jmichalenko/a70ec7a939b5608e490f412d19e15fb5 to your computer and use it in GitHub Desktop.
starter code for insertion lab
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // complete the insertion_sort function | |
| #include <cs50.h> | |
| #include <stdio.h> | |
| // function prototypes | |
| void insertion_sort(int arr[], int n); | |
| void print_array(int arr[], int n); | |
| // size of array | |
| #define SIZE 10 | |
| int main(void) | |
| { | |
| // initialize array | |
| int arr[] = {1, 8, 4, 6, 0, 3, 5, 2, 7, 9}; | |
| // sort array | |
| insertion_sort(arr, SIZE); | |
| // print out the array | |
| print_array(arr, SIZE); | |
| // done | |
| return 0; | |
| } | |
| // function to print an array | |
| void print_array(int arr[], int n) | |
| { | |
| for (int i = 0; i < n; i++) | |
| { | |
| printf("%i ", arr[i]); | |
| } | |
| printf("\n"); | |
| } | |
| // insertion sort | |
| void insertion_sort(int arr[], int n) | |
| { | |
| // TODO | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment