mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:27:45 +00:00
Userland: Add a simple /bin/sort program.
This commit is contained in:
parent
b5a1ee1d3e
commit
671dee9afa
1 changed files with 28 additions and 0 deletions
28
Userland/sort.cpp
Normal file
28
Userland/sort.cpp
Normal file
|
@ -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;
|
||||||
|
}
|
Loading…
Add table
Add a link
Reference in a new issue