Sort space-separated words alphabetically in ascending or descending order, with optional deduplication.