Posts

Showing posts from 2026

Linked list implementation in C

               It is a mostly used linear data structure in programming. Linked list has a collection of nodes and pointers. Pointers has the address of the next node. Node has the data. First node is called Head node. Last node has null pointer. Let us implement the linked list with insertion operation. Program: #include <stdio.h> #include <stdlib.h> // creation of   the node structure struct l_Node {     int n_data;     struct l_Node* next; }; //create a new node struct l_Node* createNode(int n_data) {     struct l_Node* newNode = (struct l_Node*)malloc(sizeof(struct l_Node));     if (!newNode) {         printf("Memory is not allocated\n");         exit(1);     }     newNode->n_data = n_data;     newNode->next = NUL...

Queue implementation in C

                Queue is another linear data structures . Have you stand in a queue. People who stands in the front will go first. Same principle is applicable here. This principle is called FIFO(First In First Out). Functions and variables in queue: First element denotes front. Last element represents rear. To insert an element in rear end use enqueue (). To delete an element, consider dequeue() function. ‘peek()’ is a function which makes the user to view the front element. It doesn’t delete the element. Let us create a queue using arrays in C . Program: #include < stdio.h > #include < stdlib.h > #define MAX 9    // Let us declare the maximum size of queue int queue[MAX]; int front = -1, rear = -1; // queue is full or not int isFull() {     return (rear == MAX - 1); } // Queue empty checking int isEmpty() {     return (fr...

Stack implementation in C

              Stack is a primitive data structure which has a principle of LIFO (Last In First Out).It means the last element inserted in the stack will be coming first out. Stack data structure is very much useful in memory management, expression evaluation, towers of Hanoi problem and so on. Let us implement Stack in C language as array. Basic Operations of the Stack are ‘push()’ – To insert a data ‘pop()’ – To Delete a data ‘peek()’ -It makes you to view the top data without deleting it. ‘isEmpty()’-   It checks for Stack emptiness. ‘isFull()’- It checks for Stack is full or not. Variable:   A pointer variable is called top. C Program: #include <stdio.h> #define MAX 12 int stack[MAX]; int top = -1; // let us Check if the stack is empty or not int isEmpty() {     return top == -1; } // It is used to Check if the stack is full or not int isFull() {     return top ==...

String Traversal implementation in C

       Strings are a collection of characters followed by a ‘null’ character. ’Null’ is represented by ‘\0’. In C, string  is considered as character array Syntax: To declare a string: ‘char string_name[]; To assign a value: ‘string_name[]’ = “value”; ‘value’ may be a string or set of characters as follows. a[]= “Sample”; a[15] = {‘S’,’a’,’m’,’p’,’l’,’e’,’\0’}; How to get the input and print the output? There are some built-in functions to read and write the string. ‘printf()’,’puts()’ -To print the output. ‘scanf()’,’gets()’- To get the input from the user. ‘fgets()’ – it is used to get the input from file. Built-in functions to perform String operations: ‘strlen(string)’ – it gives you the length of the string. ‘strcpy(destination, source) – It Copies source data into destination. ‘strcat(dest, src)’ – it helps in concatenation of two strings. ‘strcmp(str1, str2)’ - it Compares two strings. It returns 0 if equal, otherwise it is 1...

Array traversal implementation in C

               As we know earlier, array is a collection of similar data elements. Let us perform some array traversal implementations in C language. It contains some of the programs listed as follows. ·        Sum of array elements ·        Search an element in an array ·        Count the number of elements in the array ·        Find the maximum and minimum value in the array Sum of array elements:               This C program calculates the sum of the array elements. C Program: #include <stdio.h> int main() {     int a[10];     int i=0,n,sum=0;     printf("Enter the number of elements:");     scanf("%d",&n);     printf("Enter the elements:"); ...

Data structures implementation in C

              C is a classical Programming Language which deals with Structured programming. Data structures are the foundation concepts in Programming. When the classical Programming meets the foundations of data, here is the road map to follow to learn about the concepts. The concepts are classified into 5 types of data structures. ·        Array and Strings ·        Stacks and Queues ·        Linked List ·        Graphs ·        Trees Let us implement this one by one consequently. Array Traversal :               Array is a collection of Similar elements grouped under a common name. Eg:   ‘int a[5];’ Here ‘a’ is array which is of integer type. It has 5 elements. Let us create a array and traverse it using C ...

MYSQL statements for display database information’s:

 In this blog post, we list out some mysql functions for processing the database informations like databases linked in the mysql, its name and describe the table and its properties. Some other functions like display time,day. First, the list of databases used in the mysql can be expressed using the code ‘ SHOW DATABASES ’. mysql> SHOW DATABASES; +--------------------+ | Database            | +--------------------+ | information_schema | | my_database         | | mysql               | | performance_schema | | sakila              | | sys                 | | world               | +--------------------+ 7 ro...

MySql queries for update and delete operations

               Update is a SQL operation which updates a column or one or more column. Let us create the query.The syntax is given below. Syntax: ‘ UPDATE tablename set value1,valu2,…,valuen where condition;’ Query: single field update mysql > UPDATE Students SET age=15 WHERE name = 'Edward'; Query OK, 1 row affected (0.054 sec) Rows matched: 1   Changed: 1   Warnings: 0 Display the table contents by SELECT Query: mysql> SELECT * FROM students; +----+--------+------+ | id | name    | age   | +----+--------+------+ |   1 | ajay    |    12 | |   2 | bob     |    15 | |   3 | Edward |    15 | |   4 | Jey     |    13 | +----+--------+------+ 4 rows in set (0.009 sec) Update query : Multiple field update mysql> UPDATE Students SET name='John',age=12 WHERE id =3; Query OK, 1 ro...

Learn SQL using MySQL

       SQL – Structured Query Language . It has various commands to execute. Let us the mysql to run the SQL commands . Steps to follow: ·        MySql is open source,you can run the SQL command in this environment. ·        First, download the MySql from official website. ·        Install it in your system. ·        Login into mysql in command prompt by entering the passwords. Enter password: *********** ·        The environment is look like as follows. Welcome to the MySQL monitor.   Commands end with ; or \g. Your MySQL connection id is 21 Server version: 9.6.0 MySQL Community Server - GPL ·        First, create   a database as my_database. mysql> create database my_database; Query OK, 1 row affected (0.995 sec) ·      ...

Stock Price Predictor in java

               It is mathematical model which describes the relationship between variables. One is dependent variable and another one is independent variable . For eg: stock price predictor. Here, dependent variable is stock price. Independent variables are time, trade data and volume . The formula for predicted stock price is given by, Y= beta1+beta2*X+ error term Where, Y = predicted stock price X = predictor value ‘beta1’ = intercept ‘beta2’ = slope Error term The java implementation is given below… public class StockPricePredictor {     private double slope1;     private double intercept1;     // Train simple regression model     public void fit(double[] x, double[] y) {         if (x.length != y.length) {             throw new IllegalArgumentException ("Two...

Maze Solver in java

               It is logical thinking game. Let us implement this program in java. Maze solver can be done in many ways as follows.. This maze solver uses DFS (Depth First Search) This algorithm starts from a root node and traverses through its child node until depth. It marks the visited node as visited and continues to next node. Complete all nodes using recursion . Code: import java.util .*; public class MazeSolver {     // let us create the Maze.here, 0 = path, 1 = wall     private static int[][] maze = {         {0, 1, 0, 0, 0},         {0, 1, 0, 1, 0},         {0, 0, 0, 1, 0},         {1, 1, 0, 1, 0},         {0, 0, 0, 0, 0}     };     private static boolean[][] m_visited; ...