[PYTHON] Insertion sort of AOJ exercises

http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_1_A

Yes, exercises? I'm digesting.

a.py



#!/usr/bin/env python
# -*- coding:utf-8 -*-
#from __future__ import print_function
import time
import sys
import io
import re
import math
#i = 0
N=int(raw_input())
l=map(int, raw_input().split())
print ' '.join(map(str, l))
for j in range(1,len(l)):
    key=l[j]
    i=j-1
    while i>=0 and l[i] > key:
       l[i+1]=l[i]
       i-=1
    l[i+1]=key
    print ' '.join(map(str, l)))

I haven't seen the first submission. Make a little wasteful mistake. It's almost time for me to write something every day.

Recommended Posts

Insertion sort of AOJ exercises
Insertion sort
AOJ Sort I-
Insertion sort implementation
visualize insertion sort
Differentiation of sort and generalization of sort