cmd将永远运行python程序

时间:2015-07-12 22:25:24

标签: python cmd

出于某种原因,cmd花了2分钟来运行18行python程序。我再次跑了但是没有做任何事情。   谁能告诉我为什么要花那么长时间?

from array import *

file = open("IntegerArray.txt" , "r")

input_array = array('i')

for line in file:
    c = int(line)
    input_array.append(c)

top_array = input_array[:len(input_array)//2]
bottom_array = input_array[len(input_array)//2:]

inversion = 0
max_index = len(top_array) 

for i in range(0, max_index):
    for j in range(i + 1, max_index):
        if top_array[i] > top_array[j]:
            temp = top_array[i]
            top_array[i] = top_array[j]
            top_array[j] = temp
            inversion = inversion + 1
print "inversion = ", inversion

1 个答案:

答案 0 :(得分:0)

与时间无关,但您可以简化:

        temp = top_array[i]
        top_array[i] = top_array[j]
        top_array[j] = temp

top_array[i], top_array[j] = top_array[j], top_array[i]