Daaf
Daaf
choice = getche();
scanf("%d", &n);
if (choice == 'i') {
scanf("%d", &ai[i]);
} else {
scanf("%s", ac[i]);
mergeSort(ac, 0, n - 1, sizeof(ac[0]),
1);
getch();
return 0;
}
Prim }
#include <stdio.h>
printf("\nEdge\tWeight\n");
#define MAX 10
min = INF;
u = i;
for (i = 0; i < MAX; i++)
v = j;
visited[i] = 0;
}
}
min_cost = 0;
}
ne = 1;
}
printf("%d - %d\t%d\n", u + 1, v + 1,
printf("Enter the number of vertices:
cost[u][v]);
");
min_cost += cost[u][v];
scanf("%d", &n);
visited[v] = 1;
ne++;
printf("Enter the adjacency matrix (use
9999 for infinity):\n"); }
} printf("\nVertex\tDistance\tPrevious\n")
;
}
for (i = 0; i < n; i++) {
printf("Enter the source vertex: ");
if (dist[i] == INF)
scanf("%d", &src);
printf("%d\tINF\t\t-\n", i);
for (i = 0; i < n; i++) {
else
dist[i] = cost[src][i];
printf("%d\t%d\t\t%d\n", i, dist[i],
visited[i] = 0;
path[i]);
path[i] = src;
}
}
getch();}
dist[src] = 0;
Floyd for (k = 0; k < n; k++) {
int i, j, k; graph[i][j] = w;
}} }
0/1 knapsack void main() {
int knapsack(int W, int weights[], int printf("Enter the number of items: ");
values[], int n) {
scanf("%d", &n);
int dp[MAX_N + 1][MAX_W + 1];
printf("Enter the values of items:\n");
int i, w;
for (i = 0; i < n; i++) {
for (i = 0; i <= n; i++) {
printf("Value[%d]: ", i + 1);
for (w = 0; w <= W; w++) {
scanf("%d", &values[i]);
if (i == 0 || w == 0) {
}
dp[i][w] = 0;
printf("Enter the weights of items:\n");
} else if (weights[i - 1] <= w) {
for (i = 0; i < n; i++) {
if (values[i - 1] + dp[i - 1][w -
printf("Weight[%d]: ", i + 1);
weights[i - 1]] > dp[i - 1][w]) {
scanf("%d", &weights[i]);
dp[i][w] = values[i - 1] + dp[i -
1][w - weights[i - 1]]; }
}
getch();
}
}
return dp[n][W];
}
Bellmanford return;
#include <stdio.h> }}
scanf("%d", &graph[i][j]);
init();
getch();
}
N queen
int N; return 1;
if (board[i][j] == 1) if (solveNQueens(0))
return 0; printBoard();
else
getch();
}
Number of subsets
return;
getch();
solution[i] = 1;
}
sumOfSubsets(i + 1, sum + set[i]);
solution[i] = 0;
sumOfSubsets(i + 1, sum);
}
Graph color }
if (graphColoring(m, v + 1)) }}
if (graphColoring(m, 0)) {
printSolution();
} else {
getch();
}
Hamilton cycle hamiltonian(pos + 1);
int V; int i, j;
printf("Profit: "); }
scanf("%d", &items[i].profit);
printf("Weight: ");
scanf("%d", &items[i].weight);
items[i].ratio = (float)items[i].profit /
items[i].weight;
printf("\nOriginal Items:\n");
printf("Item\tProfit\tWeight\tRatio\n");
printf("%c\t%d\t%d\t%.2f\n", 'A' + i,
items[i].profit, items[i].weight,
items[i].ratio);
printf("Item\tProfit\tWeight\tRatio\n");
printf("%c\t%d\t%d\t%.2f\n", 'A' + i,
items[i].profit, items[i].weight,
items[i].ratio);