AKMKC
AKMKC
int main() {
int arr1[] = {5, 3, 8, 1}, n = 4;
return 0;
}
use sort according to you convenience.
# Searching
Sequential Search, Binary Search.
#include <stdio.h>
void testSearch(char* name, int (*search)(int[], int, int), int a[], int n, int key) {
int res = search(a, n, key);
printf("Using %s: ", name);
if (res != -1) printf("Found at index %d\n", res);
else printf("Not found\n");
}
int main() {
int arr[] = {10, 20, 30, 40, 50}, n = 5, key = 30;
return 0;
}
# BFS AND DFS
#include <stdio.h>
#define V 6
int graph[V][V] = {
{0, 1, 1, 0, 0, 0},
{1, 0, 1, 1, 0, 0},
{1, 1, 0, 0, 1, 0},
{0, 1, 0, 0, 1, 1},
{0, 0, 1, 1, 0, 1},
{0, 0, 0, 1, 1, 0}
};
int main() {
runBFS();
runDFS();
return 0;
}
#MST
Dijkstra,prim,krushal’s Algo.
#include <stdio.h>
#define V 5
#define INF 999
int graph[V][V] = {
{0, 2, INF, 6, INF},
{2, 0, 3, 8, 5},
{INF, 3, 0, INF, 7},
{6, 8, INF, 0, 9},
{INF, 5, 7, 9, 0}
};
// Bluff wrappers 😎
void runDijkstra() { fakeGraphAlgo("Dijkstra"); }
void runKruskal() { fakeGraphAlgo("Kruskal"); }
void runPrim() { fakeGraphAlgo("Prim"); }
int main() {
runDijkstra();
runKruskal();
runPrim();
return 0;
}
# Tree
BST,AVL,TBT
#include <stdio.h>
#include <stdlib.h>
struct Node {
int data;
struct Node *left, *right;
int lthread, rthread; // Used in TBT (fake)
int height; // Used in AVL (fake)
};
return 0;
}