Given two array A and B, sort A in such a way that the relative order among the elements will be the same as those in B
belongs to collection: Interview C++ coding problems/challenges | sorting
All Answers
                                        need an explanation for this answer? contact us directly to get an explanation for this answer
                                        
                                g
need an explanation for this answer? contact us directly to get an explanation for this answertotal answers (2)
                        
        
    
C++ programming
Algorithm:
For i=0:n2-1 //n2 be the no of elements of B&n1 of A For j=0:n1-1 && a[j]<=b[i] //maintaining the order of b if(a[j]==b[i]) inserta[j] into c; Set a[j] to 0 for avoiding duplication End if End For loop End For loopC++ program to implement relative sorting algorithm
Output
need an explanation for this answer? contact us directly to get an explanation for this answer