Wrong order Statistics Partition??

int partition(int *a,int low,int high,int index){

if(low==high)
	return a[low];

if(low<high){
	
	int temp,i=low,j=high,key=low;
	
	while(i<j){
		
		while(a[i]<=a[key]&&i<high)
			i++;
			
		while(a[j]>a[key])
			j--;
		if(i<j){	
			temp=a[i];
			a[i]=a[j];
			a[j]=temp;
		}	
	}

	temp=a[key];
	a[key]=a[j];
	a[j]=temp;
	
	if(index==j)
		return a[j];
	
	else{
		if(index<j)
			partition(a,low,j-1,index);
		
		else
			partition(a,j+1,high,index);
	}
	
}

}