In interrupted bubble sort, we need to stop the sorting based on the iteration count. This seems pretty straightforward to me. I have this code, which seems to work fine in Python, but it isn't fast enough for larger input sets. How can I make this faster?
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is", l, len(l)
print "count is ", icount
ic = 0
while ic < icount:
i = 0
while i < len(l) - 2:
if l[i + 1] < l[i]:
tup = l[i], l[i + 1]
l[i + 1], l[i] = tup
i += 1
ic += 1
print ' '.join(str(i) for i in l)
It is not fast enough for larger input sets. How can I make this faster?
In interrupted bubble sort, we need to stop the sorting based on the iteration count. This seems pretty straightforward to me. I have this code, which seems to work fine in Python.
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is", l, len(l)
print "count is ", icount
ic = 0
while ic < icount:
i = 0
while i < len(l) - 2:
if l[i + 1] < l[i]:
tup = l[i], l[i + 1]
l[i + 1], l[i] = tup
i += 1
ic += 1
print ' '.join(str(i) for i in l)
It is not fast enough for larger input sets. How can I make this faster?
In interrupted bubble sort, we need to stop the sorting based on the iteration count. This seems pretty straightforward to me. I have this code, which seems to work fine, but it isn't fast enough for larger input sets. How can I make this faster?
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is", l, len(l)
print "count is ", icount
ic = 0
while ic < icount:
i = 0
while i < len(l) - 2:
if l[i + 1] < l[i]:
tup = l[i], l[i + 1]
l[i + 1], l[i] = tup
i += 1
ic += 1
print ' '.join(str(i) for i in l)
It is not fast enough for larger input sets. How can I make this faster?
In interrupted bubble sort, we need to stop the sorting based on the iteration count. This seems pretty straightforward to me. I have this code, which seems to work fine in Python.
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is", l, len(l)
print "count is ", icount
ic = 0
while ic < icount:
print "ic is ", ic
i = 0
while i < (len(l) - 2):
if l[i+1]l[i + 1] < l[i]: l[i+1],l[i] = l[i],l[i+1]
i +=tup 1= l[i], l[i + 1]
print "inc i " l[i + 1], il[i] = tup
ic i += 1
ic += 1
print "ic' after'.join(str(i) incfor is",i ic
printin l)
It is not fast enough for larger input sets. How can I make this faster?
In interrupted bubble sort, we need to stop the sorting based on the iteration count. This seems pretty straightforward to me. I have this code, which seems to work fine in Python.
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is", l, len(l)
print "count is ", icount
ic = 0
while ic < icount:
print "ic is ", ic
i = 0
while i < (len(l) - 2):
if l[i+1] < l[i]: l[i+1],l[i] = l[i],l[i+1]
i += 1
print "inc i ", i
ic += 1
print "ic after inc is", ic
print l
It is not fast enough for larger input sets. How can I make this faster?
In interrupted bubble sort, we need to stop the sorting based on the iteration count. This seems pretty straightforward to me. I have this code, which seems to work fine in Python.
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is", l, len(l)
print "count is ", icount
ic = 0
while ic < icount:
i = 0
while i < len(l) - 2:
if l[i + 1] < l[i]: tup = l[i], l[i + 1]
l[i + 1], l[i] = tup
i += 1
ic += 1
print ' '.join(str(i) for i in l)
It is not fast enough for larger input sets. How can I make this faster?
In interrupted bubble sort, we need to stop the sorting based on the iteration count. SeemsThis seems pretty straightforward to me. I have this code, which seems to workswork fine in pythonPython.
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is" , l , len(l)
print "count is ", icount
ic = 0
while ic < icount:
print "ic is ", ic
i = 0
while i < (len(l) - 2):
if l[i+1] < l[i]: l[i+1],l[i] = l[i],l[i+1]
i += 1
print "inc i ", i
ic += 1
print "ic after inc is", ic
print l
It is not fast enough for larger input sets. How can I am wondering on how to make this faster. Any suggestions?
In interrupted bubble sort, we need to stop the sorting based on the iteration count. Seems pretty straightforward to me. I have this code, which seems to works fine in python.
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is" , l , len(l)
print "count is ", icount
ic = 0
while ic < icount:
print "ic is ", ic
i = 0
while i < (len(l) - 2):
if l[i+1] < l[i]: l[i+1],l[i] = l[i],l[i+1]
i += 1
print "inc i ", i
ic += 1
print "ic after inc is", ic
print l
It is not fast enough for larger input sets. I am wondering on how to make this faster. Any suggestions?
In interrupted bubble sort, we need to stop the sorting based on the iteration count. This seems pretty straightforward to me. I have this code, which seems to work fine in Python.
s = '36 47 78 28 20 79 87 16 8 45 72 69 81 66 60 8 3 86 90 90 | 2'
ls = s.split('|')
l = [int(n) for n in ls[0].split(' ') if n.isdigit()]
icount = int(ls[1].strip())
print "list is" , l , len(l)
print "count is ", icount
ic = 0
while ic < icount:
print "ic is ", ic
i = 0
while i < (len(l) - 2):
if l[i+1] < l[i]: l[i+1],l[i] = l[i],l[i+1]
i += 1
print "inc i ", i
ic += 1
print "ic after inc is", ic
print l
It is not fast enough for larger input sets. How can I make this faster?