0

Reverse operation in single linked list using recursion in c programming??

How to perform this program and what is the difference between recursion and the iteration??

24th Oct 2020, 3:15 AM
Jyoti
Jyoti - avatar
1 ответ
0
I write a simple example for the difference between recursion and iteration. Let's say you want to print all the integers from 1 to 10. You create a function that do that, YOU name it oneTo10. Now your function can work with a simple iteration: void oneTo10( void ) { int i; for(i=1; i<=10; ++i) { printf("%d ", i); } } Or it can work by recursion, i.e. calling itself: int oneTo10( int n ) { printf("%d ", n) if( n<10 ) { oneTo10( n+1 ); } } You need to call the recursive function giving it 1 as argument if you want to print numbers from 1 to 10. You call it in main() just once and then it calls itself nine more times to arrive to print 10. If a function contains both recursions and iterations it is still labeled as recursive. About the usage in reversing operations in linked list, i don't know. Try to explain more and to post some piece of code.
24th Oct 2020, 12:42 PM
Davide
Davide - avatar