Skip to content

Instantly share code, notes, and snippets.

@mosentest
Created October 6, 2014 03:31
Show Gist options
  • Save mosentest/e62a5687f05b38925486 to your computer and use it in GitHub Desktop.
Save mosentest/e62a5687f05b38925486 to your computer and use it in GitHub Desktop.
python
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="Encoding" useUTFGuessing="true" native2AsciiForPropertiesFiles="false" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 2.7.3 (/usr/bin/python2.7)" project-jdk-type="Python SDK" />
</project>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/helloPython.iml" filepath="$PROJECT_DIR$/.idea/helloPython.iml" />
</modules>
</component>
</project>
<component name="DependencyValidationManager">
<state>
<option name="SKIP_IMPORT_STATEMENTS" value="false" />
</state>
</component>
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="" />
</component>
</project>
__author__ = 'moziqi'
mydata = [5, 3, 2, 10, 6, 7, 4, 2, 5, 6, 7, 8, 9, 10, 1]
def bubbleSort(data):
if len(data) < 2:
return data
for i in range(0, len(data) - 1):
m = i
for j in range(i + 1, len(data)):
if (data[m] > data[j]):
m = j
print j,'\t',data
if m != i:
data[i],data[m] = data[m],data[i]
#temp=data[i],data[i]=data[m],data[m]=temp
return data
print bubbleSort(mydata),len(mydata)
__author__ = 'moziqi'
mydata = [5, 3, 2, 10, 6, 7, 4, 2, 5, 6, 7, 8, 9, 10, 1]
def insertionSort(data):
if len(data) < 2:
return data
for j in range(1, len(data)):
print j, "\t", data
key = data[j]
i = j - 1
while (i >= 0 and data[i] > key):
data[i + 1] = data[i]
i = i - 1
data[i + 1] = key
return data;
print insertionSort(mydata),len(mydata)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment