Suppose I have a list of values $S$ containing $$x_1, x_2,...,x_n$$ where each $x_i \in \Bbb R$. Suppose I order them from smallest to largest $$x_{(1)}, x_{(2)},...,x_{(n)}$$
Is there a function or an optimization problem that achieves this? Or is the median found only through a procedure of reordering?
A median is precisely a minimizer of the function $$t \mapsto \sum_{i=1}^{n}|t-x_i|.$$ (It may not be unique which is why I write a minimizer.) An optimization algorithm which does not reorder is described in Problem 1.4.11 of Kenneth Lange's MM Optimization Algorithms, SIAM.
Added: The algorithm proceeds as follows. Let $t_0$ be different from all the $x_i$. Given $k\in\{0,1,2,\ldots\}$ and $t_k$, set $w_{k,i} := 1/|t_k-x_{i}|$ and update $$t_{k+1} := \frac{\sum_{i=1}^{n}w_{k,i}x_i}{\sum_{i=1}^{n}w_{k,i}}.$$ I am not sure if this is faster than ordering, but it is interesting. There is even a variant not just for the median, but for quantiles.