diff --git a/assignment8.txt b/assignment8.txt new file mode 100644 index 0000000..8f71ca8 --- /dev/null +++ b/assignment8.txt @@ -0,0 +1,14 @@ +Caleb Gershengorn + +1: +It will print a,a (the zeroth term in the array which prints twice because it is twice not equal to 3) +I think it would then return 1 and end the function, but that seems completely wrong, but it makes sense since the code is at one point not equal to 3, thus it would return 1 and end. + +2: +Based on the logic from the first answer, none of the code from underneath the return 1 runs because the return statement has terminated the code. + +3: +Assuming that I am mistaken about the return ending the code, the lines with memory errors would be lines 27-28 and 19-20 + +4: +I honestly do not know, but I would guess that you could make the q in line 28 a dereference operator tomake sure that the memory is called and thus not lost. \ No newline at end of file diff --git a/sort.c b/sort.c new file mode 100644 index 0000000..3346f08 --- /dev/null +++ b/sort.c @@ -0,0 +1,59 @@ +#include +#include +#include +//I used the sorting algorithm pseudocode from here: https://en.wikipedia.org/wiki/Insertion_sort +int sorting(length){ + srand(time(NULL)); + int i,j,l,m,p,q,c; + int* arr1=(int*)malloc(length*4); + for (i=0;i=0&&arr2[k] > x) + { + arr2[k+1]=arr2[k]; + k=k-1; + } + arr2[k+1]=x; + } + printf("\n\nThe second array is: \n"); + for (m=0;m