Posts

Code for BUBBLE Sort

Image
1                                                      Bubble sort Ø        #include<stdio.h> #include<conio.h> void BubbleSort(int[] , int); void main() {    int array[10], n, i;    clrscr();    printf("\n\n------------------------ BUBBLE SORT -----------------------");    printf("\n\n ENTER NUMBER OF ELEMENTS : ");    scanf("%d", &n);    printf("\n");    for (i = 0 ; i < n ; i++ )    { printf("ENTER ELEMENT %d: ",i+1);      scanf("%d", &array[i]);    }    BubbleSort(array,n);    getch(); } void BubbleSort(int array[], int n) {    int i,c,j,temp;    for ( i = 0 ; i < ( n-1 ) ; i++ )    {       for ( j = 0 ; j < n-i-1 ; j++ )       {        if ( array[j] > array[j+1])        {                 temp = array[j];                 array[j] = array[j+1];                 array[j+1] = temp;        }       }       pr

Code for SELECTION Sort in C-Programming

Image
1                               Selection Sort Ø       #include<stdio.h> #include<conio.h> void SelectionSort(int[] , int); void main() {    int array[10], n, i;    clrscr();    printf("\n\n--------------------- SELECTION SORT --------------------");    printf("\n\n ENTER NUMBER OF ELEMENTS : ");    scanf("%d", &n);    printf("\n");    for (i = 0 ; i < n ; i++ )    { printf("ENTER ELEMENT %d : ",i+1);     scanf("%d", &array[i]);      }    SelectionSort(array,n);    getch(); } void SelectionSort(int array[], int n) {    int i,c,       j,temp;    for ( i = 0 ; i < ( n-1 ) ; i++ )    {       for ( j = i + 1 ; j < n ; j++ )       {            if ( array[i] > array[j])              {                 temp = array[i];                 array[i] = array[j];                 array[j] = temp;               }       }

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]);    }