Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. Java
  4. Relative Sorting

Relative Sorting

Scheduled Pinned Locked Moved Java
algorithmsdata-structureshelptutorialquestion
5 Posts 4 Posters 2 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    Harriet Muduwa
    wrote on last edited by
    #1

    Relative Sorting Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3 Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3

    P V J 4 Replies Last reply
    0
    • H Harriet Muduwa

      Relative Sorting Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3 Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3

      P Offline
      P Offline
      Pete OHanlon
      wrote on last edited by
      #2

      I can help Ramesh achieve these tasks, if Ramesh is willing to pay for someone to do Ramesh's homework for Ramesh. Alternatively, Ramesh could do some studying, and thinking, and do this all for himself.

      Advanced TypeScript Programming Projects

      1 Reply Last reply
      0
      • H Harriet Muduwa

        Relative Sorting Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3 Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3

        V Offline
        V Offline
        Victor Nijegorodov
        wrote on last edited by
        #3

        If this is a homework then:[Visual C++ General: Can you help me with my homework assignment?](https://forums.codeguru.com/showthread.php?366302-Visual-C-General-Can-you-help-me-with-my-homework-assignment&highlight=homework)

        1 Reply Last reply
        0
        • H Harriet Muduwa

          Relative Sorting Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3 Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3

          J Offline
          J Offline
          jimakoskx
          wrote on last edited by
          #4

          You gave the input but you didnt gave the output ,,for us to undertand exactly what he wants. What does he mean with 'relative order'? 2 1 2 5 7 1 9 3 6 8 8 will become 1,1,2,2,3,5,6,7,8,8,9 But i dont undertand what we want arr2 to become...so to help as i am resting in summer.

          1 Reply Last reply
          0
          • H Harriet Muduwa

            Relative Sorting Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3 Ramesh is given two arrays, arr1 and arr2. He wants to sort arr1 in such a way that the relative order of arr2 is maintained in arr1. For elements that are not present in arr2, he wants to add the these elements at the end of the array in sorted fashion. Can you help Ramesh achieve this task? Input Format First line contains two integers n and m denoting size of arrays arr1 and arr2 respectively. Second line contains n space separated integers denoting the array arr1. Third line contains m space separated integers denoting the array arr2. Output Format Print the relatively sorted arr1 Example 1 Input 11 4 2 1 2 5 7 1 9 3 6 8 8 2 1 8 3

            J Offline
            J Offline
            jimakoskx
            wrote on last edited by
            #5

            So,,, even if he mean that 2 must be first ,1 second ,8 3rd and 3 4th,,, then lets see steps from input 2 1 2 5 7 1 9 3 6 8 8 arr2[2 1 8 3] 2 ->[2] 1->[2,1] because 1 is after 2 in arr2 2->[2,2,1] or [2,1] depends if he wants/accept same that also didnt clarified. 5->[2,2,1,5] and now arr2->[21835] but if this is the case what will happen if after 5 come 0? will again start from beginning?..because say " add the these elements at the end of the array in sorted fashion" 'Sorted fashion' here mean sorted only for NEW numbers like ar2[21835]->ar2[218305] ???

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups