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
|
$(program_obj_files): %.o: %.c
|
||||||
$(CC) -c $(FLAGS) $^ -o $@
|
$(CC) -c $(FLAGS) $^ -o $@
|
||||||
|
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Unit Tests
|
# Unit Tests
|
||||||
# --------------------------
|
# --------------------------
|
||||||
unitTests:
|
unitTests: numbersTests
|
||||||
echo "needs to be implemented"
|
./numbersTests
|
||||||
|
|
||||||
|
numbersTests: numbersTests.c numbers.o bintree.o stack.o $(unityfolder)/unity.c
|
||||||
|
$(CC) $(FLAGS) -I$(unityfolder) $^ -o numbersTests
|
||||||
|
|
||||||
# --------------------------
|
# --------------------------
|
||||||
# Clean
|
# Clean
|
||||||
# --------------------------
|
# --------------------------
|
||||||
clean:
|
clean:
|
||||||
ifeq ($(OS),Windows_NT)
|
ifeq ($(OS),Windows_NT)
|
||||||
del /f *.o doble
|
del /f *.o doble numbersTests.exe
|
||||||
else
|
else
|
||||||
rm -f *.o doble
|
rm -f *.o doble numbersTests
|
||||||
endif
|
endif
|
||||||
+7
-1
@@ -38,7 +38,7 @@ unsigned int *createNumbers(unsigned int len) {
|
|||||||
if (numArray == NULL) {
|
if (numArray == NULL) {
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
// search for duplicate in code
|
// deletes duplicates and fills in with random number
|
||||||
fillarray(numArray, len);
|
fillarray(numArray, len);
|
||||||
for (unsigned int i = 0; i < --len; i++) {
|
for (unsigned int i = 0; i < --len; i++) {
|
||||||
for (unsigned int j = i; j < len; j++) {
|
for (unsigned int j = i; j < len; j++) {
|
||||||
@@ -59,8 +59,14 @@ unsigned int *createNumbers(unsigned int len) {
|
|||||||
return numArray;
|
return numArray;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Returns only the only number in numbers which is present twice. Returns zero on errors.
|
// 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) {
|
unsigned int getDuplicate(const unsigned int numbers[], unsigned int len) {
|
||||||
|
if (numbers == NULL) {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
unsigned int duplicate = 0;
|
unsigned int duplicate = 0;
|
||||||
int compare(const void *a, const void *b);
|
int compare(const void *a, const void *b);
|
||||||
int (*compareNumbers)(const void *a, const void *b) = &compare;
|
int (*compareNumbers)(const void *a, const void *b) = &compare;
|
||||||
|
|||||||
Reference in new issue
Block a user