文章插图
program addNumbers! This common program can simulate quick sortimplicit none! Type declarationsreal :: numberList(5) = (/5, 3, 7, 0, 1/)integer :: i, startLoc, endLocinterfacerecursive integer function QuickSort(list, startLoc, endLoc)real list(5)integer startLoc, endLocend function QuickSortend interface! Executable statementsstartLoc = 1endLoc = 5i = QuickSort(numberList, startLoc, endLoc)do i = 1, 5print *, numberList(i)end doend program addNumbersrecursive integer function QuickSort(list, startLoc, endLoc)real :: list(5)integer :: startLoc, endLocinteger :: low, highreal :: oriValuelow = startLochigh = endLocoriValue = http://www.kingceram.com/post/list(startLoc)if (low .ge. high) thenreturnend ifdo while(low < high)do while(low < high .and. list(high)> oriValue)high = high - 1end dolist(low) = list(high)do while(low < high .and. list(low) < oriValue)low = low + 1end dolist(high) = list(low)end dolist(low) = oriValueoriValue = http://www.kingceram.com/post/QuickSort(list, startLoc, low - 1)oriValue = QuickSort(list, low + 1, endLoc)QuickSort = lowend function QuickSort
文章插图
再加一个无聊的冒泡排序
【5没事儿就学习:快速排序(Fortran)】
program testimplicit nonereal :: list(10) = (/4, 2, 7, 3, 9, 6, 7, 1, 0, 8/)integer :: length = 10, res, iinterfaceinteger function BubbleSort(list, length)real list(10)integer lengthend function BubbleSortend interfaceres = BubbleSort(list, 10)do i = 1, 10print *, list(i)end doend program testinteger function BubbleSort(list, length)real :: list(10)integer :: innerLoof, outerLoofreal :: middledo outerLoof = 1, lengthdo innerLoof = outerLoof + 1, lengthif (list(outerLoof) > list(innerLoof)) thenmiddle = list(outerLoof)list(outerLoof) = list(innerLoof)list(innerLoof) = middleend ifend doend doBubbleSort = 1end function BubbleSort
- C站助手插件 帮您管理海量模型 就是好用
- 【Linux Mint 深度学习开发环境搭建】开发软件安装
- 宋朝就是一个穷得只剩钱的贫困朝代
- 开发者必看!探秘阿里云Hi购季开发者分会场:海量学习资源0元起!...
- UI设计师需要学习什么?从菜鸟到精英的必备课
- UART的学习记录
- 赵光义谋杀赵匡胤其实早就被一位女人所暗示
- 别一说茅台就只知道酒,茅台还有这些! 世界吉尼斯记录茅台
- 最奇葩的吉尼斯世界记录,墙都不扶就扶你们 解乳罩吉尼斯记录
- 6 大数据处理技术导论 | Datawhale组队学习46期