+ 2
Can you find a problem?
#include <iostream> void swap(int& a, int& b, int arr[]){ int temp = arr[a]; arr[b] = temp; arr[a] = arr[b]; } int recursion(int i, int count){ int arr[6]{8,7,3,5,2,2}, size = *(&arr + 1) - arr, *p = arr; if(arr[i - 1] > arr[i]){ swap(arr[i - 1], arr[i], p); count++; } else count++; if(i == size && count > 20){ for(int i = 0; i < size; ++i){ std::cout << arr[i] << " "; } return 0; } if(i == size) return recursion(i = 0, count); else return recursion(i += 1, count); } int main() { recursion(1, 0); return 0; } Doesn't output anything.
8 Answers
+ 2
krow here you go:
https://code.sololearn.com/cdpR7P3Fi96d/?ref=app
+ 2
it must output items from array, but in sorted way
+ 2
krow, i have just shared wrong link, sorry, you can try now
+ 2
krow, I should edit my recursion:) You changed my mind, for sure. Btw It must order and output here.
+ 1
Please, save your code on "CodePlayground" section then post his link here
+ 1
I have made this for your understanding of your problem... I have divided output and sorting in two different function
https://code.sololearn.com/cCkZzvGKJ5CZ/?ref=app
Sorting use selection sort algorithm https://www.sololearn.com/learn/658/?ref=app
0
It output the array items... What your code would be do?
0
Oleg Storm I dont understand logic of your recursion function... Anyway it must order the array or output only? It must be maded recursively?