Posts

Showing posts from September, 2019

Code for Doubly Linked List C-programing

#include<stdio.h> #include<conio.h> #include<stdlib.h> struct node {  int data;  struct node *next;  struct node *prev; }; struct node *head; void InsertAtBeginning(int x) {  struct node *ptr = (struct node *)malloc(sizeof(struct node));  ptr->next = NULL;  ptr->prev = NULL;  ptr->data = x;  if(ptr==NULL)  {   printf("\n MEMORY NOT AVAILABLE");  }  if(head==NULL)   {    head = ptr;   }  else  {   ptr->next = head;   head->prev=ptr;   head = ptr;  } } void InsertAtEnd(int y) {  struct node *ptr = (struct node *)malloc(sizeof(struct node));  struct node *temp;  ptr->data = y;  ptr->next = NULL;  ptr->prev = NULL;  if(ptr==NULL)  {   printf("\n MEMORY NOT AVAILABLE");  }  if(head==NULL)  {   head = ptr;  }  else  {  temp = head;  while(temp->next!=NULL)  {   temp = temp->next;  }  temp->next = ptr;  ptr->prev = temp;  ptr->next = NULL;  } }

Code for Circular Linked List c-programing

#include<stdio.h> #include<conio.h> #include<stdlib.h> struct node {  int data;  struct node *next; }; struct node *head; void InsertAtBeginning(int x) {  struct node *temp = (struct node *)malloc(sizeof(struct node));  struct node *temp2 = head;  temp->data = x;  temp->next = NULL;  if(temp==NULL)  {   printf("\n MEMORY UNAVAILABLE");  }  if(head==NULL)  {   head = temp;   temp->next = head;  }  if(temp2->next!=head)  {   temp2 = temp2->next;  }  temp->next = head;  head = temp;  temp2->next = head; } void InsertAtEnd(int y) {  struct node *temp = (struct node *)malloc(sizeof(struct node));  struct node *temp2;  temp->data = y;  temp->next = NULL;  if(temp==NULL)  {   printf("\n MEMORY UNAVAILABLE");  }  if(head==NULL)  {   head = temp;   temp->next = head;  }  while(temp2->next!=head)  {   temp2 = temp2->next;  }  temp2->next = temp;  temp->n

Code for Simple LINKED LIST in C-Programming

#include<stdio.h> #include<conio.h> #include<stdlib.h> struct node {  int data;  struct node *next; }; struct node *head; void insertb(int x) {  struct node *temp=(struct node *)malloc(sizeof(struct node));  if(temp==NULL)  {   printf("memory unavailable");  }  temp->data=x;  temp->next=NULL;  if(head!=NULL)  {   temp->next=head;  }  head=temp; } void inserte(int x) {  struct node *t1=head;  struct node *temp=(struct node *)malloc(sizeof(struct node));  temp->data=x;  temp->next=NULL;  if(temp==NULL)  {   printf("memory unavailable");  }  if(head==NULL){   head=temp;  }  while(t1->next!=NULL)  {   t1=t1->next;  }  t1->next=temp; } void insertn(int x,int index) {   struct node *temp1=(struct node *)malloc(sizeof(struct node));   struct node *temp2;   int i=0;   temp1->data=x;   temp1->next=NULL;   if(index==1)   {    temp1->next=head;    head=temp1;   }  

Code for simply QUEUE

#include<stdio.h> #include<conio.h> void qinsert(int q[],int  n,int *f,int *r,int x) {  if(*r>=(n-1))  { printf("queue is overflow");   return;  }  *r=*r+1;  q[*r]=x;  if(*f==-1)  *f=0; } int qdelete(int q[],int *f,int *r) { int a;  if(*f==-1)   return 0;  else  {   if(*f==*r)   {    *f=-1;    *r=-1;   }   else   {    a=q[*f];    *f=*f+1;   }    return(a);  } } void display(int q[],int *f,int *r) { int i;  if(*f==-1) printf("queue is empty");   else   { printf("\nthe queue contains:\n");    for(i=*f;i<=*r;i++)    { printf("%d ",q[i]);    } getch();   } } void main() { int n=5,*f,*r,i,j,k; intq[5];  *f=-1;  *r=-1; clrscr();  again: printf("\n1.insert\n2.delete\n3.display\n4.exit"); printf("enter your choice\n"); scanf("%d",&k);  switch(k)  {   case 1: printf("enter the value to be inserted\n"); scanf("%d",

Code for Circular Queue

#include<stdio.h> #include<conio.h> void qinsert(int q[],int n,int *f,int *r,int x) {  if(*r>=(n-1) && *f==0 || *f==*r+1 )  { printf("queue is overflow");   return;  }  else  { if(*r==n-1 && *f>0)   {    *r=0;    q[*r]=x;   }   else   {    *r=*r+1;    q[*r]=x;   }  if(*f==-1)   *f=0;  } } int qdelete(int q[],int n,int *f,int *r) { int a;  if(*f==-1)   return 0;  else  {   if(*f==*r)   {    *f=-1;    *r=-1;   }   else   { if(*f==n-1 && *r<*f)    {     a=q[*f];     *f=0;    }    else    {     a=q[*f];     *f=*f+1;    }   }    return(a);  } } void display(int q[],int n,int *f,int *r) { int i;  if(*f==-1) printf("queue is empty");  else  { printf("\nqueue contains:\n");   if(*f<=*r)   {    for(i=*f;i<=*r;i++)    { printf("%d\t",q[i]);    }   }   else   {    for(i=0;i<=*r;i++)    { printf("%d\t",q[i]);    }  

Code For Double-Ended Queue (DQUEUE)

#include<stdio.h> #include<conio.h> void insert_left(int q[],int *f,int  x) {  if(*f<=0)  { printf("insertion is not possible\n");  }  else  {   *f=*f-1;   q[*f]=x;  } } int delete_left(int  q[],int *f,int *r) { int a;  if(*f==-1)   return 0;  else  {   if(*f==*r)   {    *f=-1;    *r=-1;   }   else   {    a=q[*f];    *f=*f+1;   }   return a;  } } void insert_right(int q[],int n,int *f,int *r,int x) {  if(*r>=n-1) printf("queue is overflow\n");  else  {   *r=*r+1;   q[*r]=x;  }  if(*f==-1)   *f=0; } int delete_right(int q[],int  *f,int  *r) { int  a;   if(*r==-1)    return 0;   else   {    if(*f==*r)    {     *f=-1;     *r=-1;    }    else    {     a=q[*r];     *r=*r-1;    }     return a;   } } void display(int q[],int n,int *f,int *r) { int i;  if(*f==-1) printf("queue is empty");  else  { printf("\nqueue contains:\n");   if(*f<=*r)   {    for(