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; | |
struct Queue{ | |
int size; | |
int rear; | |
int front; | |
}; | |
void passing_pointer(struct Queue *p){ |
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; | |
struct Node{ | |
struct Node *prev; | |
int data; | |
struct Node *next; | |
}*start=NULL,*last=NULL; | |
void insert(int ele){ |
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; | |
struct Node{ | |
int data; | |
struct Node *next; | |
}*start=NULL; | |
void ins(int ele){ | |
struct Node *p = start; |
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; | |
struct Node { | |
int data; | |
struct Node *next; | |
}*start=NULL; | |
typedef struct Node node; |
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; | |
int fib(int n){ | |
if(n<=1){return n;}else{ | |
return fib(n-2) + fib(n-1); | |
} | |
} | |
int main(){ |
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; | |
int power(int m, int n){ | |
if(n==0){ return 1;}else{ | |
return power(m,n-1) * m; | |
} | |
} | |
int main(){ |
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; | |
int recursive_fact(int n){ | |
/* | |
ex: fact(n) = 1*2*3........*(n-1)*n | |
so, (fact(n-1)*n) Gives us the answer | |
*/ |
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; | |
int sum_function(int last){ | |
static int sum = 0; | |
for(int i=1;i<=last;i++){ | |
sum += i; | |
} | |
return sum; | |
} |
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 << " "; | |
} | |
} |
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 <stdio.h> | |
#include <stdlib.h> | |
int max(int a,int b){ | |
return (a>b) ? a : b; | |
} | |
void knapsack(int n, int W, int val[], int wt[]){ | |
int i,w; | |
int K[n+1][W+1]; |