Move element to end

PHOTO EMBED

Sun Jul 12 2020 21:30:28 GMT+0000 (UTC)

Saved by @gagandeepgarg6 #java

public static List<Integer> moveElementToEnd(List<Integer> array, int toMove) {	
  int i = 0;
  int j = array.size()-1;
		
  while(i < j){
			
	while( i < j && array.get(j) == toMove)
		j--;
	if(array.get(i) == toMove)
	   swap(i,j, array);
		
    i++;							
  }		
	return array;		
  }
	
public static void swap(int i, int j, List<Integer> array ){
			
  int temp = array.get(i);
  array.set(i, array.get(j));			
  array.set(j, temp);
}
content_copyCOPY