Skip to content

Instantly share code, notes, and snippets.

@manojnaidu619
Created June 20, 2019 12:35
Show Gist options
  • Save manojnaidu619/df6d1d8e766a7f9be0c6dfb28e3c0f54 to your computer and use it in GitHub Desktop.
Save manojnaidu619/df6d1d8e766a7f9be0c6dfb28e3c0f54 to your computer and use it in GitHub Desktop.
Head and Tail Recursion in CPP
#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