The simulated $((1-\alpha )\times 100)^{th}$ percentiles of the null distribution of a specific statistic I've written this algorithm in R program:

as following
n=20
mu=100
sigma=10
N=10000
alpha=0.05     
D=array(0, dim=N)
for(j in 1:N){
    x=rnorm(n,mu,sigma)
    x=sort(x) 
    z=dnorm(x, mean(x), sd(x))  # R can do it at once
    num = sum( abs(z - seq(1,n)/n ) ) 
    den = sum( pmax(z, seq(1,n)/n) )
    D[j]=num/den
}
sort(D)[N*alpha]

The output is $0.4690684$. But it must be about $0.1232$. Is there something wrong in my code?
Thanks in advance.

@jbowman is right.
delta <- vector()
for (i in 1:10000){
x <- rnorm(20, 100, 10)
x <- sort(x)
z <- pnorm(x, mean(x), sd(x))
delta[i] <- sum(abs(z-seq(1,20)/20))/sum(pmax(z, seq(1,20)/20))
}
plot(density(delta))
quantile(delta, 1-0.05)

