Common sorted list: Difference between revisions

From Rosetta Code
Content added Content deleted
(Created page with "{{Draft task}} Given an integer array '''nums''', the goal is create common sorted list with unique elements. For example: <br> '''nums''' = [5,1,3,8,9,4,8,7],[3,5,9,8,4],[1,...")
 
No edit summary
Line 3: Line 3:


For example:
For example:
<br> '''nums''' = [5,1,3,8,9,4,8,7],[3,5,9,8,4],[1,3,7,9]
<br> '''nums''' = [5,1,3,8,9,4,8,7], [3,5,9,8,4], [1,3,7,9]
<br> '''output''' = [1,3,4,5,7,8,9]
<br> '''output''' = [1,3,4,5,7,8,9]



Revision as of 07:40, 24 February 2021

Common sorted list is a draft programming task. It is not yet considered ready to be promoted as a complete task, for reasons that should be found in its talk page.

Given an integer array nums, the goal is create common sorted list with unique elements.

For example:
nums = [5,1,3,8,9,4,8,7], [3,5,9,8,4], [1,3,7,9]
output = [1,3,4,5,7,8,9]

Ring

<lang ring> nums = [[5,1,3,8,9,4,8,7],[3,5,9,8,4],[1,3,7,9]] sumNums = []

for n = 1 to len(nums)

   for m = 1 to len(nums[n])
       add(sumNums,nums[n][m])
   next

next

sumNums = sort(sumNums) for n = len(sumNums) to 2 step -1

   if sumNums[n] = sumNums[n-1]
      del(sumNums,n)
   ok

next

sumNums = sort(sumNums)

see "common sorted list elements are: " showArray(sumNums)

func showArray(array)

    txt = ""
    see "["
    for n = 1 to len(array)
        txt = txt + array[n] + ","
    next
    txt = left(txt,len(txt)-1)
    txt = txt + "]"
    see txt

</lang>

Output:
common sorted list elements are: [1,3,4,5,7,8,9]