我如何使2D列表的选择排序

时间:2019-11-26 16:15:59

标签: python algorithm list sorting selection-sort

#P = number of Posts P[i][j].timestamp -> where i Person and j the Posting and the timestamp 
#N = Number of posts we need (the length for the loops)
# Implement your algorithm . Dont use sorted or sort. Sort by timestamp
def Sort(P, N):

    for number_post in range(N):

      # Find the lowest Date in List
        person = number_post
        j = number_post

        for i in range(number_post+1, N):
            if P[person][j].timestamp > P[person][i].timestamp:
                    person = i

       # If lower swap the Elements in List       
            temp = P[person][number_post].timestamp
            P[person][number_post].timestamp = P[person][i].timestamp
            P[person][i].timestamp = temp
    #Einfügen in den Newsfeed
            S[N] = temp

    #S = [P[0][0], P[1][0],  P[1][1]]

    # TODO end
    return S

0 个答案:

没有答案