Generalizing stack sorting and $c$-sorting for permutations, we define the permutree algorithm. Given two disjoint subsets $U$ $D$ of $\{2, \dots, n-1\}$, $(U,D)$-permutree tries to sort permutation $\pi \in \mathfrak{S}_n$ fails if only there are $1 \le i < j k n$ such that $\pi$ contains subword $jki$ $j U$ $kij$ D$. This algorithm is seen as a way explore an automaton which either rejects al...