[R] what is wrong with my quicksort?

warc conny-clauss at gmx.de
Sun Sep 4 03:51:20 CEST 2011


Hey guys,
I tried to program quicksort like this but somethings wrong.

please help


	
>partition <- function(x, links, rechts){
>	
>	i <- links
>	j <- rechts
>	t <- 0						
>	pivot <- sample(x[i:j],1)
>	
>	while(i <= j){
>		
>		while(x[i] <= pivot){	
>			i = i+1}
>			
>		while(x[j] >= pivot){	
>			j = j-1}
>			
>		if( i <= j){			
>			
>			t = x[i]
>			x[i] = x[j]
>			x[j] = t
>			
>			i=i+1
>			j=j-1
>			
>			}
>			print(pivot)	
>		
>		
>		}
>	#Rekursion
>	
>	if(links < j){				
>		partition(x, links, j)}			
>	if(i < rechts){				
>		partition(x, i, rechts)}
>	
>	return(x)
>	}
>	
>
>quicksort <- function(x){
>		
>
>		
>		partition(x, 1, length(x))
>}



thx

--
View this message in context: http://r.789695.n4.nabble.com/what-is-wrong-with-my-quicksort-tp3788681p3788681.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list