Call by Value and Call by reference Program

GTU Data Structure Practical – 1 Introduction to pointers. Call by Value and Call by reference. Call by Value #include void swap(int,int); int main() { int a,b; printf(“nEnter a Value of A=”); scanf(“%d”,&a); printf(“nEnter a Value of B=”); scanf(“%d”,&b); swap(a,b); printf(“nOld Values:”); printf(“A=%d B=%d n”,a,b); } void swap(int p,int q) { int tmp; tmp=p; p=q; […]

Implement LCS problem.

GTU ADA Practical – 12 Implement LCS problem. #include void lcs(int arr[][10], char ar[], int, int); int l, k; void main() { char s1[10], s2[10]; int i, j; printf(“nEnter the stringsnX = “); s1[0] = 0; char ch = getchar(); while (ch != ‘n’) { s1[++l] = ch; ch = getchar(); } printf(“Y = “); […]

Kruskal’s Algorithm Implementation

GTU ADA Practical – 11 Implement Kruskal’s Algorithm #include using namespace std; class edge { public: int w = 0, e1 = 0, e2 = 0; }; int main() { int n; char c = ‘a’; int k = 0; cout > n; int g[n][n]; int stree[n][n], snode[n]; edge e[n * n]; // defalut values […]

Prim’s Algorithm Implementation

GTU ADA Practical – 10 Implement prim’s algorithm #include using namespace std; int main() { int n; char c = ‘a’; cout > n; int g[n][n]; int stree[n][3]; for (int i = 0; i < n; i++) stree[i][0] = stree[i][1] = stree[i][2] = -1; cout

Graph and Searching Implementation

GTU ADA Practical – 9 Implementation of Graph and Searching (DFS and BFS). Graph and Searching Implementation using DFS #include int a[20][20], reach[20], n; void dfs(int v) { int i; reach[v] = 1; for (i = 1; i

Knapsack Problem Using Greedy Method

GTU ADA Practical – 8 Implementation of a knapsack problem using greedy algorithm #include #include int main() { int m, n, i, j; printf(“Enter maximum weight of knapsack “); scanf(“%d”, &m); printf(“nEnter number of objects “); scanf(“%d”, &n); int wt = 0, k = 0; float cal[n], p[n], w[n], x[n], prof = 0; for (i […]

Making Change Problem using Dynamic Programming

GTU ADA Practical – 7 Implementation of making a change problem using dynamic programming #include #include int main() { int m, n, i, j; printf(“Enter the amount of which you want changen”); scanf(“%d”, &m); printf(“nEnter the number of determinantsn”); scanf(“%d”, &n); int c[n + 1][m + 1], dc[n + 1]; printf(“nEnter the determinantsn”); dc[0] = […]

C Program for Matrix Chain Multiplication

GTU ADA Practical – 6 Implementation of chain matrix multiplication using dynamic programming. #include #include void sel(int arr[5][5], int, int); int n, i, j, s[10][10]; int main() { int l, k, q; printf(“Enter number of matricesn”); scanf(“%d”, &n); int p[n + 1], m[n + 1][n + 1]; printf(“nEnter P array valuesn”); for (i = 0; […]

Knapsack Problem Using Dynamic Programming

GTU ADA Practical – 5 Implementation of a knapsack problem using dynamic programming. #include #include int W, n; void main() { int w, i, l = 0, p, j; printf(“Enter number of objects n”); scanf(“%d”, &n); printf(“Enter maximum weight, knapsack can carry n”); scanf(“%d”, &W); int k[n + 1][W + 1], a[W], v[W], ks[W]; printf(“Enter […]