Slip 1
Slip 1
ANS:-
#include <stdio.h>
#include <stdlib.h>
return root;
}
int main() {
Node* root = NULL;
int choice, data;
do {
printf("\nMenu:\n");
printf("1. Insert\n");
printf("2. Inorder Traversal\n");
printf("3. Exit\n");
printf("Enter your choice: ");
scanf("%d", &choice);
switch (choice) {
case 1:
printf("Enter data to insert: ");
scanf("%d", &data);
root = insert(root, data);
break;
case 2:
printf("Inorder Traversal: ");
inorder(root);
printf("\n");
break;
case 3:
printf("Exiting program.\n");
break;
default:
printf("Invalid choice! Please enter a valid option.\n");
}
} while (choice != 3);
return 0;
}
Q.2) Write a C program that accepts the vertices and edges of a graph and stores it
as an adjacency matrix. Display the adjacency matrix. Implement functions to print
indegree of all vertices of graph.
ANS:-
#include <stdio.h>
#include <stdlib.h>
int adjMatrix[MAX_VERTICES][MAX_VERTICES];
int indegree[MAX_VERTICES];
int main() {
int vertices, edges, i;
int start, end;
initializeGraph(vertices);
displayAdjMatrix(vertices);
printIndegree(vertices);
return 0;
}