# [R](https://www.r-project.org), 56 bytes

```r
\(e,d,l,u=e<d,`+`=sort)c(c(d,l[i<-!(l>e)-u])+!u,l[!i]+u)
```

[Attempt This Online!](https://ato.pxeger.com/run?1=fY1BCsIwFETX9RRml0_nQ2MbrNB4ELVQSBMoFAq1OY2bKHgob2OKXbuZgXkzzOM5x5c377B4rj_1TTr0GBGMa3p0eWfu07yQlVam-Do0LOR4dsShpVyEFImhzQNt-4uXBfYlsszKCnwAaySpoKCJdivlP1RDpXmiCiWOOEGptc-qoO0hxp9_AQ)