summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <awesomekling@gmail.com>2019-04-26 00:53:57 +0200
committerAndreas Kling <awesomekling@gmail.com>2019-04-26 00:53:57 +0200
commit671dee9afa2e65b8887c50f74311b3782516083d (patch)
tree8c705059aba3030fcedbb3adf8319dfde3c278c9
parentb5a1ee1d3e0b7c14cee2fce44bde8c0c3cb7f330 (diff)
downloadserenity-671dee9afa2e65b8887c50f74311b3782516083d.zip
Userland: Add a simple /bin/sort program.
-rw-r--r--Userland/sort.cpp28
1 files changed, 28 insertions, 0 deletions
diff --git a/Userland/sort.cpp b/Userland/sort.cpp
new file mode 100644
index 0000000000..35d3933f9e
--- /dev/null
+++ b/Userland/sort.cpp
@@ -0,0 +1,28 @@
+#include <AK/QuickSort.h>
+#include <AK/Vector.h>
+#include <AK/AKString.h>
+#include <stdio.h>
+#include <stdlib.h>
+
+int main(int argc, char** argv)
+{
+ Vector<String> lines;
+
+ for (;;) {
+ char buffer[BUFSIZ];
+ auto* str = fgets(buffer, sizeof(buffer), stdin);
+ if (!str)
+ break;
+ lines.append(buffer);
+ }
+
+ quick_sort(lines.begin(), lines.end(), [] (auto& a, auto& b) {
+ return strcmp(a.characters(), b.characters()) < 0;
+ });
+
+ for (auto& line : lines) {
+ fputs(line.characters(), stdout);
+ }
+
+ return 0;
+}