int scrambled( unsigned int a[], unsigned int b[], unsigned int len )
{
int smallest, j, temp;
int scramble = 1;
//sorts a[]:
for(int i =0; i<len-1; i++){
smallest = i;
for( int k=i+1; k<len; k++){
if(a[k] < a[smallest]){
smallest = k;
}
}
temp = a[i];
a[i]=a[smallest];
a[smallest] = temp;
}
//sorts b[]:
for(int i =0; i<len-1; i++){
smallest = i;
for( int k=i+1; k<len; k++){
if(b[k] < b[smallest]){
smallest = k;
}
}
temp = b[i];
b[i]=b[smallest];
b[smallest] = temp;
}
//compares a[] with b[]:
for(int i =0; i<len; i++){
if(a[i] != b[i]){
scramble = 0;
break;
}
}
return scramble;
}
No comments:
Post a Comment