aboutsummaryrefslogtreecommitdiff
path: root/util/array.c
diff options
context:
space:
mode:
authorDrew DeVault <sir@cmpwn.com>2018-07-16 20:10:38 -0700
committerGitHub <noreply@github.com>2018-07-16 20:10:38 -0700
commit7f20ab644347b11fd8242beaf7a6fe42c910d014 (patch)
tree808d0e88c28561d5853be09f7c2ab7968ce70e3f /util/array.c
parent4984ea49eeaa292d66be9e535d93a4d8185f3e18 (diff)
parent9a6f77fc2ceb59f4b5bcd1e1f8c00aa974b5192b (diff)
Merge pull request #960 from Ongy/tablet
tablet-unstable-v2 support
Diffstat (limited to 'util/array.c')
-rw-r--r--util/array.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/util/array.c b/util/array.c
new file mode 100644
index 00000000..9ee39d33
--- /dev/null
+++ b/util/array.c
@@ -0,0 +1,21 @@
+#include <stdlib.h>
+#include <stdint.h>
+
+// https://www.geeksforgeeks.org/move-zeroes-end-array/
+size_t push_zeroes_to_end(uint32_t arr[], size_t n) {
+ size_t count = 0;
+
+ for (size_t i = 0; i < n; i++) {
+ if (arr[i] != 0) {
+ arr[count++] = arr[i];
+ }
+ }
+
+ size_t ret = count;
+
+ while (count < n) {
+ arr[count++] = 0;
+ }
+
+ return ret;
+}