Posts

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...