Created
June 20, 2019 12:35
-
-
Save manojnaidu619/df6d1d8e766a7f9be0c6dfb28e3c0f54 to your computer and use it in GitHub Desktop.
Head and Tail Recursion in CPP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
void head(int x){ | |
if(x>0){ | |
fun(x-1); | |
cout << x << " "; | |
} | |
} | |
void tail(int x){ | |
if(x>0){ | |
cout << x << " "; | |
fun(x-1); | |
} | |
} | |
int main(){ | |
head(3); // 1 2 3 | |
tail(3); // 3 2 1 | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment