python和C语言分别实现插入排序
2023-09-14 08:57:59 时间
代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-- 1 def InsertSort(numbers,n): for i in range(1,n): j = i-1 tem = numbers[i] while numbers[j] tem and j =0: numbers[j+1] = numbers[j] j -= 1 else: numbers[j+1] = tem print "Onthe sort:",numbers a = [9,8,7,6,5,4,3,2,1,0] print "BeforeSort:",a InsertSort(a, 10) print "After Sort:",a
最后输出为:
BeforeSort: [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]
Onthe sort: [8, 9, 7, 6, 5, 4, 3, 2, 1, 0]
Onthe sort: [7, 8, 9, 6, 5, 4, 3, 2, 1, 0]
Onthe sort: [6, 7, 8, 9, 5, 4, 3, 2, 1, 0]
Onthe sort: [5, 6, 7, 8, 9, 4, 3, 2, 1, 0]
Onthe sort: [4, 5, 6, 7, 8, 9, 3, 2, 1, 0]
Onthe sort: [3, 4, 5, 6, 7, 8, 9, 2, 1, 0]
Onthe sort: [2, 3, 4, 5, 6, 7, 8, 9, 1, 0]
Onthe sort: [1, 2, 3, 4, 5, 6, 7, 8, 9, 0]
Onthe sort: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
After Sort: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
C语言实现代码:
代码Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-- #include stdio.h void insertSort(int a[10],int n) int i,j,k; for(i=1;i i++) int tem = a[i]; j = i - 1; while(a[j] tem j =0) a[j+1] = a[j]; j--; a[j+1] = tem; for(k=0;k k++) printf("%d",a[k]); printf("\n"); int main() int b[10] = {9,8,7,6,5,4,3,2,1,0}; int i; for(i=0;i i++) printf("%d",b[i]); printf("\n"); insertSort(b,10); for(i=0;i i++) printf("%d",b[i]); }
最后输出:
9876543210
8976543210
7896543210
6789543210
5678943210
4567893210
3456789210
2345678910
1234567890
0123456789
LeCun自曝使用C语言23年之久,2年前才上手Python,还曾短暂尝试Lua 云栖号资讯:【点击查看更多行业资讯】在这里您可以找到不同行业的第一手的上云资讯,还在等什么,快来! 程序员圈子的流行风潮,过几年就怀旧风走一波。 这不,最近Twitter上刮起了一阵编程语言使用历史的风潮。
Python: C语言 C语言是一门面向过程的、抽象化的通用程序设计语言,广泛应用于底层开发。C语言能以简易的方式编译、处理低级存储器。C语言是仅产生少量的机器语言以及不需要任何运行环境支持便能运行的高效率程序设计语言。
相关文章
- 【Python】python 多线程两种实现方式
- 【Python】python 日期操作
- 第三百五十节,Python分布式爬虫打造搜索引擎Scrapy精讲—selenium模块是一个python操作浏览器软件的一个模块,可以实现js动态网页请求
- Python MySQLdb模块连接操作mysql数据库实例_python
- python: easyocr的安装和使用(easyocr 1.6.2 / Python 3.7.15 )
- python:ERROR: No matching distribution found for Pillow==9.1.0的处理(Python 3.6.8)
- Python语言学习:Python语言学习之python包/库package的简介(模块的封装/模块路径搜索/模块导入方法/自定义导入模块实现华氏-摄氏温度转换案例应用)、使用方法、管理工具之详细攻略
- Python语言学习:Python语言学习之python包/库package的简介(模块的封装/模块路径搜索/模块导入方法/自定义导入模块实现华氏-摄氏温度转换案例应用)、使用方法、管理工具之详细攻略
- Python:利用python语言实现18位身份证号码和15位身份证号码相互转换
- Python之tkinter:动态演示调用python库的tkinter带你进入GUI世界(Canvas)
- Python的IDE:基于Eclipse/MyEclipse软件的PyDev插件配置python的开发环境(不同python项目加载不同版本的python)—从而实现Python编程图文教程之详细攻略
- Python语言学习:利用python语言实现调用内部命令(python调用Shell脚本)—命令提示符cmd的几种方法
- Python语言学习之字符串那些事:python和字符串的使用方法之详细攻略
- 〖Python自动化办公篇⑲〗 - python实现邮件自动化 - 邮件发送
- 〖Python自动化办公篇㉑〗- python实现邮件自动化 - 定时发送邮件
- 【python采集】把网站排行榜shipin内容通通采集
- python飞机大战演示+完整源码(再送大量项目源码)
- Python编程:shelve模块-持久化python数据
- python基础===八大排序算法的 Python 实现
- Python kafka操作实例(kafka-python)
- 〖Python自动化办公篇⑲〗 - python实现邮件自动化 - 邮件发送
- 〖Python自动化办公篇㉑〗- python实现邮件自动化 - 定时发送邮件
- 每日一练2——排序问题(Python&C语言实现)
- python 使用PIL模块将文字写入到图片上