Anonymous user
Sorting algorithms/Bubble sort: Difference between revisions
→{{header|CMake}}: Reach O(n**2). Old code was closer to O(n**3).
(→{{header|CMake}}: Add 12th CMake example -- but only for lists of integers.) |
(→{{header|CMake}}: Reach O(n**2). Old code was closer to O(n**3).) |
||
Line 420:
<lang cmake># bubble_sort(var [value1 value2...]) sorts a list of integers.
function(bubble_sort var)
▲ math(EXPR last "${last} - 1") # last = last index of ARGN
set(again YES)
while(again)
set(again NO)
math(EXPR last "${last} - 1") # Decrement last index.
foreach(index RANGE
math(EXPR index_plus_1 "${index} + 1")
if(a GREATER "${b}")
set(again YES)
endif()
endforeach(index)
endwhile()
set(${var} "${ARGN}" PARENT_SCOPE)▼
set(answer)
math(EXPR last "${ARGC} - 1")
foreach(index RANGE 1 "${last}")
list(APPEND answer "${ARGV${index}}")
endforeach(index)
endfunction(bubble_sort)</lang>
|