Posts

Showing posts from May, 2023

Data Structures(Circular Queues)

  #include <stdio.h>       # define max 6    int  queue[max];   // array declaration    int  front=-1;   int  rear=-1;   // function to insert an element in a circular queue    void  enqueue( int  element)   {        if (front==-1 && rear==-1)    // condition to check queue is empty        {           front=0;           rear=0;           queue[rear]=element;       }        else   if ((rear+1)%max==front)   // condition to check queue is full        {           printf( "Queue is overflow.." );       }        else        {           rear=(rear+1)%max;        // rear is incremented            queue[rear]=element;      // assigning a value to the queue at the rear position.        }   }      // function to delete the element from the queue    int  dequeue()   {        if ((front==-1) && (rear==-1))   // condition to check queue is empty        {           printf( "\nQueue is underflow.." );       }     else   if (front==rear)   {      printf( "

Data Structures(Queues using Linked List)

  #include<stdio.h>    #include<stdlib.h>   struct node    {        int  data;        struct node *next;   };   struct node *front;   struct node *rear;    void  insert();   void  delete();   void  display();   void  main ()   {        int  choice;         while (choice !=  4 )        {              printf( "\n*************************Main Menu*****************************\n" );           printf( "\n=================================================================\n" );           printf( "\n1.insert an element\n2.Delete an element\n3.Display the queue\n4.Exit\n" );           printf( "\nEnter your choice ?" );           scanf( "%d" ,& choice);            switch (choice)           {                case   1 :               insert();                break ;                case   2 :               delete();                break ;                case   3 :               display();                break ;                case   4

Data Structures(Stacks using Linked List)

  #include <stdio.h>   #include <stdlib.h>   void  push();   void  pop();   void  display();   struct node    {   int  val;   struct node *next;   };   struct node *head;      void  main ()   {        int  choice= 0 ;          printf( "\n*********Stack operations using linked list*********\n" );       printf( "\n----------------------------------------------\n" );        while (choice !=  4 )       {           printf( "\n\nChose one from the below options...\n" );           printf( "\n1.Push\n2.Pop\n3.Show\n4.Exit" );           printf( "\n Enter your choice \n" );                 scanf( "%d" ,&choice);            switch (choice)           {                case   1 :               {                    push();                    break ;               }                case   2 :               {                   pop();                    break ;               }                case   3 :               {