dt
BAN USER
Comments (6)
Reputation 10
Page:
1
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
Comment hidden because of low score. Click to expand.
0
of 0 vote
import java.io.*;
class eg11{
public static void main(String args[])throws IOException{
int[] src = new int[]{1,0,2,3};
int[] trg = new int[]{0,2,3,1};
System.out.println("the no of steps required for conversion are:"+rearranged(src,trg));
}
public static int rearranged(int[] src,int[] trg){
int count=0;
int k = findElement(0,src);
int l = findElement(0,trg);
while(k!=l){
int m = trg[k];
int n = findElement(m,src);
src[n] = 0;
src[k] = m;
k = n;
count++;
}
return count;
}
public static int findElement(int n,int[] a){
int i;
for(i=0;i<a.length;i++){
if(a[i]==n)break;
}
return i;
}
}
Comment hidden because of low score. Click to expand.
Page:
1
CareerCup is the world's biggest and best source for software engineering interview preparation. See all our resources.
i think it depends not only on the memory available but the available memory should be contiguous too
- dt August 17, 2013