I will detail some of the issues that exist in bogosort and linearsearch.
bogosort.c:
Will not compile due to error on line 6, but has several other issues that need addressing.
int bogosort(yarr){}
is missing a type specifier for yarr
so defaults to int yarr
, but you are passing it a pointer int * yarr
. The actual implementation of bogosort does not make much sense either, as you do not actually sort any of the values in the array, nor do any checks to see if the array has been sorted.
for(i1 = 1; i < sizeof(yarr); i++) { static; }
here it seems like you want to make i
have the same size of the array but later on you set it to 0 anyway. Also using the 'static' specifier here makes no sense. I don't think sizeof(yarr)
does what you think it does. You cant get the size of an array in C with just sizeof(array). It is better to either pass the length of the array with the array, e.g in a struct, or use something like sizeof(array)/sizeof(array[0]).
for(int i = 0; i < sizeof(yarr); i++)
{
//I couldn't do yarr[i] or yarr[i1], so i did math
do
{
int random_shuffle = rand() % yarr-yarr+i + yarr-yarr+i1;
} while(yarr-yarr+i < yarr-yarr+i1);
}
Again sizeof(yarr)
. Also, this yarr-yarr+i + yarr-yarr+i1
is simply the same as writing i + i1
, which i dont think you intended. Besides, if you had passed a pointer as intended then you would be able to access the values in the array using operator []. Ignoring the sizeof issues, this loop would only run for one iteration due to the condition in the while loop. There are some other small problems but you should be able to sort them out. I recommend compiling with -Wall to see all warnings, and -Werror if you want to be strict with your code, as -Werror will not let you compile if there are warnings.
linearsearch.c
Again using sizeof array wrong. Also using int to hold char values. Finally, the actual implementation will not work as intended as C neither supports comparing whole strings using just the == operator or doing something like int *yarr = {"Shluck much", "much Shluck"};
. Even if the loop runs, it will probably always return 1. Again recommend compiling with -Wall and -Werror to root out these sorts of issues.
As a side not, it is better to only push your commits if they successfully compile first or mark the commit/pull request as WIP so others know not to expect a fully working implementation.