Code golf: combining multiple sorted lists into a single sorted list

前端 未结 26 1951
余生分开走
余生分开走 2020-12-29 12:42

Implement an algorithm to merge an arbitrary number of sorted lists into one sorted list. The aim is to create the smallest working programme, in whatever language you like.

26条回答
  •  时光取名叫无心
    2020-12-29 12:57

    VB

    The setup:

    Sub Main()
        f(New Int32() {1, 4, 7}, _
          New Int32() {2, 5, 8}, _
          New Int32() {3, 6, 9})
    End Sub
    

    The output:

    Sub f(ByVal ParamArray b As Int32()())
        Dim l = New List(Of Int32)
        For Each a In b
            l.AddRange(a)
        Next
        For Each a In l.OrderBy(Function(i) i)
            Console.WriteLine(a)
        Next
    End Sub
    

提交回复
热议问题