diff options
| author | Thomas Schmucker <ts@its1.de> | 2021-12-30 11:01:32 +0100 |
|---|---|---|
| committer | Thomas Schmucker <ts@its1.de> | 2021-12-30 11:01:32 +0100 |
| commit | 214f0923ba2981649f14ec3761662332df446d9d (patch) | |
| tree | a400269f616ed53cf378b7ac77bf1f486113c796 | |
| parent | 5e696c74c9649b0e54133d46a3ae92e5ce0632fb (diff) | |
| download | data-structures-214f0923ba2981649f14ec3761662332df446d9d.tar.gz data-structures-214f0923ba2981649f14ec3761662332df446d9d.tar.bz2 data-structures-214f0923ba2981649f14ec3761662332df446d9d.zip | |
code cleanup
| -rw-r--r-- | arraylist.c | 10 | ||||
| -rwxr-xr-x | insertsort | bin | 0 -> 18008 bytes | |||
| -rw-r--r-- | stack.c | 4 |
3 files changed, 10 insertions, 4 deletions
diff --git a/arraylist.c b/arraylist.c index a8cebb0..cb23e94 100644 --- a/arraylist.c +++ b/arraylist.c | |||
| @@ -91,6 +91,8 @@ ArrayList_growIfNeeded(struct ArrayList *arrayList) | |||
| 91 | 91 | ||
| 92 | assert(arrayList->array); | 92 | assert(arrayList->array); |
| 93 | } | 93 | } |
| 94 | |||
| 95 | assert(arrayList->capacity > arrayList->size); | ||
| 94 | } | 96 | } |
| 95 | 97 | ||
| 96 | void | 98 | void |
| @@ -111,7 +113,9 @@ ArrayList_insertAt(struct ArrayList *arrayList, size_t idx, T *ptr) | |||
| 111 | 113 | ||
| 112 | ArrayList_growIfNeeded(arrayList); | 114 | ArrayList_growIfNeeded(arrayList); |
| 113 | 115 | ||
| 114 | memmove(&arrayList->array[idx + 1], &arrayList->array[idx], (arrayList->size - idx) * sizeof(arrayList->array[0])); | 116 | memmove(&arrayList->array[idx + 1], |
| 117 | &arrayList->array[idx], | ||
| 118 | (arrayList->size - idx) * sizeof(arrayList->array[0])); | ||
| 115 | arrayList->array[idx] = ptr; | 119 | arrayList->array[idx] = ptr; |
| 116 | ++arrayList->size; | 120 | ++arrayList->size; |
| 117 | } | 121 | } |
| @@ -152,7 +156,9 @@ ArrayList_removeAt(struct ArrayList *arrayList, size_t idx, void clear_func(T *, | |||
| 152 | } | 156 | } |
| 153 | 157 | ||
| 154 | #if defined(ARRAYLIST_KEEP_ORDER) | 158 | #if defined(ARRAYLIST_KEEP_ORDER) |
| 155 | memmove(&arrayList->arrayList[idx], &arrayList->arrayList[idx + 1], (arrayList->size - (idx + 1)) * sizeof(arrayList->arrayList[0])); | 159 | memmove(&arrayList->arrayList[idx], |
| 160 | &arrayList->arrayList[idx + 1], | ||
| 161 | (arrayList->size - (idx + 1)) * sizeof(arrayList->arrayList[0])); | ||
| 156 | #else | 162 | #else |
| 157 | arrayList->array[idx] = arrayList->array[arrayList->size - 1]; | 163 | arrayList->array[idx] = arrayList->array[arrayList->size - 1]; |
| 158 | #endif | 164 | #endif |
diff --git a/insertsort b/insertsort new file mode 100755 index 0000000..32576ac --- /dev/null +++ b/insertsort | |||
| Binary files differ | |||
| @@ -47,10 +47,10 @@ stack_push(struct stack *stack, T data) | |||
| 47 | bool | 47 | bool |
| 48 | stack_pop(struct stack *stack, T *data) | 48 | stack_pop(struct stack *stack, T *data) |
| 49 | { | 49 | { |
| 50 | if ( stack->head != NULL ) { | 50 | if ( stack->head ) { |
| 51 | struct stack_item *next = stack->head->next; | 51 | struct stack_item *next = stack->head->next; |
| 52 | 52 | ||
| 53 | if ( data != NULL ) { | 53 | if ( data ) { |
| 54 | *data = stack->head->data; | 54 | *data = stack->head->data; |
| 55 | } | 55 | } |
| 56 | free(stack->head); | 56 | free(stack->head); |
