Posts

Maze Solver in C

               It is a classical project. It is implemented by the use of graph traversal algorithm. It mainly finds the path from starting point to the end point. Here, maze is represented as a 2D matrix. Walls are marked as 1 and paths are marked as 0. C implementation: ·        It starts from including header file. ·        First, the rows and columns are defined as 5. ·        Maze is initialized with values. ·        Visited value is created. ·        solveItMaze() function is used to solve the maze. ·        This function is used to visit all the rows and columns to find the path. The path starts from starting point to end point. ·        Main() function checks for path is not equal to 0,0. ·        ...

Student Information System Project using Linked List and BST in C

               Let us create a simple project for Student Information System. It uses a Linked list and Binary Search Tree. //   First, a student structure is created with rollno, name ,marks and a pointer next. #include <stdio.h> #include <stdlib.h> #include <string.h> // Let us   create Student structure typedef struct Student {     int s_rollno;     char s_name[50];     float s_marks;     struct Student *next;    // Self Referential structure } Student; // BST Node structure is created typedef struct BST_Node {     Student *student;     struct BST_Node *left, *right; } BST_Node; Student *head = NULL;    // Linked List head is assigned as NULL BST_Node *root = NULL;    // BST root // create function to memory allocation Student* createStudent(int roll, char nam...

Representation of Graph using adjacency list in C

     This is the next type of graph representation. In the previous post, the adjacency matrix is used to represent the graph. You can visit the below link to access the adjacency matrix. https://rajeeva84.blogspot.com/2026/05/representation-of-graph-using-adjacency.html It makes use of linked list . It uses vertexes. It   #include <stdio.h> #include <stdlib.h>   struct g_Node {     int g_vertex;     struct g_Node* g_next; }; struct Graph {     int num_Vertices;     struct g_Node** adjLists; }; // let us Create a node struct g_Node* createNode(int v) {     struct g_Node* newNode = malloc(sizeof(struct g_Node));     newNode->g_vertex = v;     newNode->g_next = NULL;     return newNode; } // here, is the graph code struct Graph* createGraph(int vertices) {     struct ...

Representation of Graph using adjacency matrix in C

              Graph is a non-linear data structure. It can be represented by adjacency matrix or adjacency list. Let us discuss the methods in detail. This blog post deals with the first method Adjacency matrix. Adjacency matrix:               It is a two-dimensional matrix.it deals with the edges present between nodes.   If the edges found, it assigns the weight as 1. Otherwise, it values it as 0. Code implementation: This code includes the built-in header file. It defines the vertices as 4. A function ‘Display_Matrix()’ is used to represent the graph. ‘main()’ function initialises the graph. It assigns the value for matrix.  Finally,it calls the ‘Display_Matrix’ function to display the output. Code: #include <stdio.h> #define V 4   // Declare the number of vertices void Display_Matrix(int graph[V][V]) {     for (int i = 0; ...

How to find a height of a binary tree and counting the leaf nodes in C?

               Binary tree is a tree which has two nodes. It has a root node. It has a left sub tree and right sub tree. Let us implement the c program to count the leaf nodes and height of a binary tree. C implementation:               This implementation starts by including header files. Next, declare the node structure for tree. It has node with data, left and right values. Now, a new node is created by allocating its memory. The values are initialised.   To calculate the heights of the tree, traverse the tree. To count the leaf nodes, check the root nodes, traverse each sub tree separately and count the nodes. In the main() function, create the root node and all child nodes by using the newNode() function. Call the height() function and countLeafNodes() function to display the output. C Code: #include <stdio.h> #include <stdlib.h> // D...

How to delete a node in Binary Search Tree?

               As we discussed the basic operations in Binary Search Tree , here we implement the delete operation in Binary Search Tree . Deletion can be implemented as three types. ·        Node has one child – you can replace the node with its child node. ·        Node has two children – it changes the node to the smallest value in the right                                                 Subtree and deleted the successor. ·        Node has no child – it deletes the node. #include <stdio.h> #include <stdlib.h> // Create   BST node struct BST_Node {     int b_data;     ...

Binary Search Tree operations in C

               Binary Search Tree is a binary Tree which follows a unique key and tree ordering. It strictly follows the left and right nodes values should be in order in such that it satisfies the binary tree condition. Let us implement the searching in Binary Search Tree in C language. Program implementation: It includes the header files. The Node is created first. It has a data, left child and right child. To create a node , memory should be allocated. The data, left, right node pointers are assigned with the node. Next, insert function is created. It reads the data and assigns the left and right pointer. Search function is implemented. It gets the value from the user. It checks the value in the tree. If the value is found, it displays the found message. Otherwise, it displays not found message. Finally, it prints the value.   C Code: #include <stdio.h> #include <stdlib.h> struct BST_Node { ...