+ 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.

31st Aug 2018, 8:34 AM
Oleg Storm
Oleg Storm - avatar
8 odpowiedzi
31st Aug 2018, 9:08 AM
Oleg Storm
Oleg Storm - avatar
+ 2
it must output items from array, but in sorted way
31st Aug 2018, 9:11 AM
Oleg Storm
Oleg Storm - avatar
+ 2
krow, i have just shared wrong link, sorry, you can try now
31st Aug 2018, 9:17 AM
Oleg Storm
Oleg Storm - avatar
+ 2
krow, I should edit my recursion:) You changed my mind, for sure. Btw It must order and output here.
31st Aug 2018, 10:04 AM
Oleg Storm
Oleg Storm - avatar
+ 1
Please, save your code on "CodePlayground" section then post his link here
31st Aug 2018, 9:01 AM
KrOW
KrOW - avatar
+ 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
31st Aug 2018, 10:27 AM
KrOW
KrOW - avatar
0
It output the array items... What your code would be do?
31st Aug 2018, 9:10 AM
KrOW
KrOW - avatar
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?
31st Aug 2018, 9:37 AM
KrOW
KrOW - avatar