Run Code
|
API
|
Code Wall
|
Users
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
bubble sort
//clang 3.8.0 #include <iostream> void bubbleSort(int *nums,int size){ for(int i=0;i<size;++i ){ bool swapped=false; for(int y=0;y<size-i-1;++y ){ if(nums[y]>nums[y+1]){ std::swap(nums[y],nums[y+1]); swapped=true; } } if(!swapped) break; } } void printArray(int *nums,int size){ for(int i=0;i<size;++i ) std::cout<<nums[i]<<" "; } int main() { int nums[]={9,8,7,4,3,6}; int size=sizeof(nums)/sizeof(nums[0]); bubbleSort(nums,size); printArray(nums,size); }
run
|
edit
|
history
|
help
0
Please
log in
to post a comment.
function returning a function demo
ljblblljkl
Vector of pointer of P...
Uno
even number
6 14 15 17 21 33 29
INHERIT_CTORS default constructor
C++ out of ref
std::function ambiguity clang
Exploring stringstreams
Please log in to post a comment.