forked from freudenreichan/info2Praktikum-DobleSpiel
comitting number.c
This commit is contained in:
1 parent
bde3ed1062
commit
2285230f8a
2 files changed
+15
-5
No files matched your search
+8
-4
@@ -32,18 +32,22 @@ doble : main.o $(program_obj_files)
|
||||
$(program_obj_files): %.o: %.c
|
||||
$(CC) -c $(FLAGS) $^ -o $@
|
||||
|
||||
|
||||
# --------------------------
|
||||
# Unit Tests
|
||||
# --------------------------
|
||||
unitTests:
|
||||
echo "needs to be implemented"
|
||||
unitTests: numbersTests
|
||||
./numbersTests
|
||||
|
||||
numbersTests: numbersTests.c numbers.o bintree.o stack.o $(unityfolder)/unity.c
|
||||
$(CC) $(FLAGS) -I$(unityfolder) $^ -o numbersTests
|
||||
|
||||
# --------------------------
|
||||
# Clean
|
||||
# --------------------------
|
||||
clean:
|
||||
ifeq ($(OS),Windows_NT)
|
||||
del /f *.o doble
|
||||
del /f *.o doble numbersTests.exe
|
||||
else
|
||||
rm -f *.o doble
|
||||
rm -f *.o doble numbersTests
|
||||
endif
|
||||
+7
-1
@@ -38,7 +38,7 @@ unsigned int *createNumbers(unsigned int len) {
|
||||
if (numArray == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
// search for duplicate in code
|
||||
// deletes duplicates and fills in with random number
|
||||
fillarray(numArray, len);
|
||||
for (unsigned int i = 0; i < --len; i++) {
|
||||
for (unsigned int j = i; j < len; j++) {
|
||||
@@ -59,8 +59,14 @@ unsigned int *createNumbers(unsigned int len) {
|
||||
return numArray;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
||||
unsigned int getDuplicate(const unsigned int numbers[], unsigned int len) {
|
||||
if (numbers == NULL) {
|
||||
return 0;
|
||||
}
|
||||
unsigned int duplicate = 0;
|
||||
int compare(const void *a, const void *b);
|
||||
int (*compareNumbers)(const void *a, const void *b) = &compare;
|
||||
|
||||
Reference in new issue
Block a user