Monday, 14 November 2011

Single ended Queue

#include<stdio.h>
void create(void);
void delete(void);
void display(void);
#define qmax 5
int q[qmax];
int r=-1;
int f=0;
char s[5];
int main()
{
//////////////////
while(1)
{
system("clear");
printf("\n\n\n-------------------------Single-Ended-Queue---------------------------------\n\n");

printf("\n\n                       1)    Enter Queue ");
printf("\n\n                       2)    Display");
printf("\n\n                       3)    Delete");
printf("\n\n                       4)    Exit");

printf("\n\n\n-----------------------------------------------------------------\n\n");
printf("\n\nEnter the choice  :");


int x;
scanf("%d",&x);
switch(x)
{
    case 1:
    {
    create();
    break;
    }
    case 2:
    {
    display();
    break;
    }
    case 3:
    {
    delete();
    break;
    }
    case 4:
    {
    return;
    }
    default:
    {printf("\n\nEnter valid Choice  :\n\n");
         printf("\n\n\n\n\n\nPress any Key  :\n");
         gets(s);
         gets(s);
    break;}
}
}
}

//////////////////////////////////////////////////////////////////
void create(void)
{
int data;
if(r==(qmax-1))
{
 printf("\n\nQueue is over flow\n");
 printf("\n\n\n\n\n\nPress any Key  :\n");
 gets(s);
 gets(s);
 return;
}
r=r+1;
printf("\n\nEnter the Queue data   :");
scanf("%d",&data);
q[r]=data;
}

/////////////////////////////////////////////////////////////
void delete(void)
{
if(f>r)
 {
  printf("\n\nQueue is under flow");
  printf("\n\n\n\n\n\n\nPress any Key  :\n");
  gets(s);
  gets(s);
  return;
 }
f=f+1;
if(f>r)
{
f=0;
r=-1;
}
}


void display(void)
{
int i;
if(f==0&&r==-1)
{
 printf("--->-Queue is now free---->-");
 printf("\n\n\n\n\n\n\nPress any Key  :\n");
 gets(s);
 gets(s);
 return;
}


printf("\n\n\n\nrear end------>");
for(i=f;i<=r;i++)
  {
  printf("%d-----",q[i]);  
  }
printf("front end--->\n\n\n\n\n\n\nPress any Key  :\n");
gets(s);
gets(s);
}

/////////////////////////////////////////////////////////////////



Application--Polinomial addition

#include<stdio.h>
#include<stdlib.h>
////structure      //////////
struct Poly
    {
    struct Poly *next;
    int exp;
    int coeff;
    };

/////////////Functions declaration ///////////
struct Poly* CreatePoly();
struct Poly* AddPoly(struct Poly* ,struct Poly*);
void DisplayPoly(struct Poly*);
/////Main /////////////
int main()
{
while(1)
{
system("clear");
    struct Poly *P1,*P2,*P3;
    int x;
    char s[5];
    printf("\n\n\n-------------------Polynomial  Addition ----------------\n\n");   
    printf("        1)   Enter First Polynomial Details\n");   
    printf("        2)   Enter Second Polynomial Details\n");   
    printf("        3)   Exit  \n ");
    printf("--------------------------------------------------------\n");   
    printf("Enter the chioce  :");   
    scanf("%d",&x);
switch(x)
{   
case 1:
    {
    P1 = CreatePoly();
    break;
    }
case 2:   
    {
    P2 = CreatePoly();
    P3 = AddPoly(P1,P2);
    system("clear");
        printf("\n\n\n\n\nFirst Polynomial        :  ");
    DisplayPoly(P1);
    printf("\n\nSecond Polynomial       :  ");
    DisplayPoly(P2);
    printf("\n--------------------------------------------------");
    printf("\n\nResult                  :  ");
    DisplayPoly(P3);
    printf("\n\n\n\n\n\n\nPress Any Key to return :");
    gets(s);
    gets(s);
    break;
    }
case 3:   
    {
    return 0;
    }
default:
    {
    printf("Enter valid choice\n");
    printf("\n\n\n\n\n\n\nPress Any Key to return :");
    gets(s);
    gets(s);
    }

}
}
}
////////Function Definition /////////////////
void DisplayPoly(struct Poly* P)
{   
    while(P != NULL)
    {
        printf("+(%d)x^%d ",P->coeff,P->exp);
        P = P->next;
    }
}

struct Poly* CreatePoly()
{
    int count;
    struct Poly* start=NULL,*new=NULL;
    struct Poly* temp=NULL;
    printf("\nEnter the number of Polynomial terms: ");
    scanf("%d",&count);
    while(count--)
          {
        new = malloc( sizeof(struct Poly) );
        printf("\nTerm %d:\nCoefficient  : ",count+1);
        scanf("%d",&new->coeff);
        printf("Exponent      ");
        scanf("%d",&new->exp);

        if(start == NULL || start->exp < new->exp)
         {
            new->next = start;
            start = new;
         }
        else
         {
          temp = start;
            while(temp->next != NULL && temp->next->exp > new->exp)
                temp = temp->next;   
       
            new->next = temp->next;
            temp->next = new;
        }
          }
    return start;
}
   
struct Poly* AddPoly( struct Poly* P1, struct Poly* P2)
{
    struct Poly* P3_start = NULL;
    struct Poly* P3,*temp;
   
    while(P1 != NULL && P2 != NULL )
    {
          temp = malloc( sizeof(struct Poly) );
      temp->next=NULL;   
        if(P3_start == NULL)
        {
            P3_start = temp;
            P3 = temp;
        }
        else
        {
            P3->next = temp;
            P3 = P3->next;
        }
       
        if( P1->exp > P2->exp)
        {
            temp->exp = P1->exp;
            temp->coeff = P1->coeff;
            P1 = P1->next;
        }
        else if(P1->exp < P2->exp)
        {
            temp->exp = P2->exp;
            temp->coeff = P2->coeff;
            P2 = P2->next;
        }
        else if(P1->exp == P2->exp)
        {
            temp->exp = P1->exp;
            temp->coeff = P1->coeff + P2->coeff;
            P1 = P1->next;
            P2 = P2->next;
        }
   
    }
       
    while(P1 != NULL) {
               
        temp = (struct Poly*)malloc( sizeof(struct Poly) );
        temp->coeff = P1->coeff;
        temp->exp = P1->exp;
        P1 = P1->next;
       
        P3->next = temp;
        P3 = P3->next;
    }
    while(P2 != NULL) {
           
        temp = (struct Poly*)malloc( sizeof(struct Poly) );
        temp->coeff = P2->coeff;
        temp->exp = P2->exp;
        P2 = P2->next;
       
        P3->next = temp;
        P3 = P3->next;
    }
   
    return P3_start;

}

Circular Link list


   
    ///////   Created   By  ///////////////////////////////
    ///                                                        ///
    ///                                                        ///
    ///     MUHAMMED ISMAIL  PP     ///
    ///                                                       ///
    ///                                                       ///
    /////////////////////////////////////////////////////////////



#include<stdio.h>
#include<stdlib.h>
void create(void);
void sorted_create(void);
void display(void);
void insert_first(void);
void insert_btwn(int x);
void delete(int data);
void reverse(void);
char s[5];    
       struct clist
        {
        int data;
    struct clist *next;
    }*start=NULL;
///////////////////Main////////////////////////////////////////
int main()
{   
while(1)
{
system("clear");
printf("\n");
printf("                ---------------------Circular Link List Data Structure------------- \n\n");
printf("                                 1--Create \n\n");
printf("                                     2--view \n\n");
printf("                             3--insert\n\n");
printf("                             4--Delete\n\n");
printf("                                 5--Reverse\n\n");
printf("                                6--Exit\n\n");
printf("                ------------------------------------------------------------------- \n\n");
int x;
int i;
printf("Enter choice   :");
    scanf("%d",&x);
switch(x)
    {
     case 1:
     {
system("clear");
    printf("\nSelect your choice :\n");
    printf("\n--------------------------------------------\n");
    printf("\n        1)---Create Normal Structure :\n");
    printf("\n        2)---Create Sorted Structure :\n");
    printf("\n--------------------------------------------\n");
    scanf("%d",&x);
    switch (x)
    {
        case 1:
         {
        printf("\n\n\nEnter the number of elements  :");
         scanf("%d",&x);
           for(i=0;i<x;i++)
           {
            printf("\nEnter the  data %d = ",i+1);
                 create();
           }
   
        printf("\nYour Data Structure  Successfully Created");
            printf("\n-----------------------------------\n");
               sleep(1);
        break;
          }
        case 2:
        {
         printf("\n\n\nEnter the number of elements  :");
                 scanf("%d",&x);
                   for(i=0;i<x;i++)
                   {
                    printf("\nEnter the  data %d = ",i+1);
                    sorted_create();
                   }

                printf("\nYour Data Structure  Successfully Created");
                printf("\n-----------------------------------\n");
                sleep(1);
                break;
        }
      }
       break;
     }   
      case 2:
    {
    gets(s);
    display();
    break;
    }
      case 3:
    {
    printf("\nEnter the position :");
    scanf("%d",&x);
      if(x==1)
          {
     insert_first();
      }
      else
      {
     insert_btwn(x);
      }
    break;
        }
      case 4:
    {
     printf("\nEnter the data for delete  : ");
     scanf("%d",&x);
      gets(s);
     delete(x);
     break;
    }   
      case 5:
    {
     reverse();
     printf("\nYour Data Structure  Successfully Reversed\n");
         printf("-------------------------------------------\n");
     sleep(2);
    break;
    }
      case 6:       
    {
    return;
    break;
    }
      default:
    {
    gets(s);
    printf("\n\nEnter  valid Choice : Press Any Key to Return :  ");
    gets(s);
    break;
    }

}

}
return ;
}
///////////////////////Create//////////////////////////////////

void create(void)
{
   struct clist *temp,*tr;
    temp=malloc(sizeof(struct clist));
    scanf("%d",&temp->data);
    temp->next=NULL;
    if(start==NULL)
    {
    start=temp;
    temp->next=temp;
    }   
    else
    {
    tr=start;
        while(tr->next !=start)
            {
        tr=tr->next;
        }
    
    tr->next=temp;
    temp->next=start;
    }
}

/////////////////////////////////////////////////////////////////////
void display(void)
{
    char s[5];
int ct=0;
       printf("\n\n\n\n\n\n\n             START\n");   
       printf("              |\n");
       printf("              |\n");
       printf("              |\n");
       printf("              |\n");
       printf("              ");
        struct clist *tr;
    tr=start;
    if(start==NULL)
    {
        printf("-->  No Data");

    }
       else
       {
    while (tr->next!=start)
    {
        printf("-->  %d ",tr->data);
    tr=tr->next;
    ct=ct+7;
    }
        printf("-->  %d",tr->data);       //to print  last element
       ct=ct+7;
      }
///////////
if(start!=NULL)
{
printf("\n");
printf("%*c",15,'|');
printf("%*c\n",ct,'|');
printf("%*c",15,'|');
printf("%*c\n",ct,'|');
printf("%*c",15,'|');
printf("%*c\n",ct,'|');
printf("%*c",15,'<');
int i;
for(i=0;i<ct;i++)
{printf("-");}
}
//////////////////

 printf("\n\n\n\n\n\n\nPRESS ENTER KEY");
 gets(s);
}



////////////////////////////////////////////////////////////////////////
void insert_first(void)
{
    struct clist *temp,*tr;
    temp=malloc(sizeof(struct clist));
        printf("\nEnter the data : ");
    scanf("%d",&temp->data);
    tr=start;
    temp->next=start;
        while(tr->next!=start)       
        {
        tr=tr->next;
        }
    tr->next=temp;
    start=temp;


    printf("\nYour Data  Successfully  Saved in First Position");
        printf("\n-----------------------------------\n");
        sleep(1);
}
///////////////////////////////////////////////////////////////////////
void insert_btwn(int x)
{
int i;   
    struct clist *tr,*temp;
    tr=start;
    for(i=0;i<x-2;i++)
    {
     tr=tr->next;
    }
    temp=malloc(sizeof(struct clist));
    printf("\nEnter the data : ");
    scanf("%d",&temp->data);
    temp->next=tr->next;
    tr->next=temp;
        printf("\nYour Data  Successfully Saved in  Position %d ",x);
        printf("\n-----------------------------------\n");
        sleep(1);
}
////////////////////////////////////////////////////////////////////////

void delete(int data)
{
 struct clist *temp,*tr;
        ////////// if only one data /////////////
    if(start->next==start&&start->data==data)
    {
    temp=start;
    start=NULL;
    free(temp);
        printf("\nYour Data1 %d is  Successfully Deleted ",data);
        printf("\n-----------------------------------\n");
        sleep(2);
    return;
          }
    tr=start->next;
    ////////// data in starting positoin ///////
    if(tr->data==data)
            {
         temp=tr;
         start->next=temp->next;
         free(temp);
            printf("\nYour Data2 %d is  Successfully Deleted ",data);
                printf("\n-----------------------------------\n");
                 sleep(2);
         return;
        }

        ////////// if middle ////////////////////////////////
    while(tr->next!=start)
         {
        if(tr->next->data==data)
         {
         temp=tr->next;
         tr->next=temp->next;
         free(temp);
         printf("\nYour Data3 %d is Successfully Deleted",data );
                printf("\n----------------------------------\n");
                sleep(2);
        return ;
         }
        tr=tr->next;
        }
        ///////// Last //////////////////////////////////////      
     if(tr->next->data==data)
        {
        temp=tr->next;
        tr->next=temp->next;
        free(temp);
        start=tr;
        printf("\nYour Data4 %d is Successfully Deleted",data);
        printf("\n----------------------------------\n");
        sleep(2);
        }
    else
        {
        printf("\nThis data not exist");
        printf("\n\n\n\n\n\n\n\n\npress any key ");
        gets(s);
        }       
   
}
//////////////Reverse /////////////////////////////////////////////////

void reverse(void)
{
struct clist *temp,*tr0,*tr;
temp=malloc(sizeof(struct clist));
tr=tr0=start;
temp=start->next;
start->next=NULL;
    while(temp!=start)
    {
    tr=temp;
    temp=temp->next;
    tr->next=tr0;
    tr0=tr;
    }
  start->next=tr; 
  start=tr;
          
}
////////////////////////////////////////////////////////////////////////

void sorted_create(void)
{
struct clist *temp,*tr;
temp=malloc(sizeof(struct clist));
scanf("%d",&temp->data);
temp->next=NULL;
if(start==NULL||start->data>temp->data)
 {
   if(start==NULL)
   {
    start=temp;
    start->next=start;
   }
    start->next=temp;
    temp->next=start;
    start=temp;
    return;
 }
else
{
  tr=start;


while(tr->next!=start&&tr->next->data<temp->data)
    {
    tr=tr->next;
    }
temp->next=tr->next;
tr->next=temp;
}
}

Double Link


   
    ///////   Created   By  //////////////////////////////
    ///                                                         ///
    ///                                                        ///
    ///     MUHAMMED ISMAIL  PP     ///
    ///                                                        ///
    ///                                                         ///
    //////////////////////////////////////////////////////////////



#include<stdio.h>
#include<stdlib.h>
void create(void);
void sorted_create(void);
void display(void);
void insert_first(void);
void insert_btwn(int x);
void delete(int data);
void reverse(void);
char s[5];    
       struct dlist
        {
        int data;
    struct dlist *next;
    struct dlist *previous;
    }*start=NULL;
///////////////////Main////////////////////////////////////////
int main()
{   
while(1)
{
system("clear");
printf("\n");
printf("                ---------------------Double List Data Structure-------------------- \n\n");
printf("                                 1--Create \n\n");
printf("                                     2--view \n\n");
printf("                             3--insert\n\n");
printf("                             4--Delete\n\n");
printf("                                 5--Reverse\n\n");
printf("                                6--Exit\n\n");
printf("                ------------------------------------------------------------------- \n\n");
int x;
int i;
printf("Enter choice   :");
    scanf("%d",&x);
switch(x)
    {
     case 1:
     {
system("clear");
    printf("\nSelect your choice :\n");
    printf("\n--------------------------------------------\n");
    printf("\n        1)---Create Normal Structure :\n");
    printf("\n        2)---Create Sorted Structure :\n");
    printf("\n--------------------------------------------\n");
    scanf("%d",&x);
    switch (x)
    {
        case 1:
         {
        printf("\n\n\nEnter the number of elements  :");
         scanf("%d",&x);
           for(i=0;i<x;i++)
           {
            printf("\nEnter the  data %d = ",i+1);
                    create();
           }
   
        printf("\nYour Data Structure  Successfully Created");
            printf("\n-----------------------------------\n");
               sleep(2);
        break;
          }
        case 2:
        {
         printf("\n\n\nEnter the number of elements  :");
                 scanf("%d",&x);
                   for(i=0;i<x;i++)
                   {
                    printf("\nEnter the  data %d = ",i+1);
                    sorted_create();
                   }

                printf("\nYour Data Structure  Successfully Created");
                printf("\n-----------------------------------\n");
                sleep(2);
                break;
        }
      }
       break;
     }   
      case 2:
    {
    gets(s);
    display();
    break;
    }
      case 3:
    {
    printf("\nEnter the position :");
    scanf("%d",&x);
      if(x==1)
            { insert_first();}
      else
        { insert_btwn(x); }
    break;
        }
      case 4:
    {
     printf("\nEnter the data for delete  : ");
     scanf("%d",&x);
      gets(s);
     delete(x);
     break;
    }   
      case 5:
    {
    reverse();
    break;
    }
      case 6:       
    {
    return;
    break;
    }
      default:
    {
    gets(s);
    printf("\n\nEnter  valid Choice : Press Any Key to Return :  ");
    gets(s);
    break;
    }

}

}
return ;
}
///////////////////////Create//////////////////////////////////
void create(void)
{
   struct dlist *temp,*tr;
    temp=malloc(sizeof(struct dlist));
    scanf("%d",&temp->data);
    temp->next=NULL;
    temp->previous=NULL;
   
    if(start==NULL)
    {
    start=temp;
    }   
    else
    {
    tr=start;
        while(tr->next !=NULL)
            {
        tr=tr->next;
        }
    
    tr->next=temp;
    temp->previous=tr;
    }

}

/////////////////////////////////////////////////////////////////////
void display(void)
{
    char s[5];
       printf("\n\n\n\n\n\n\n             START\n");   
       printf("              |\n");
       printf("              |\n");
       printf("              |\n");
       printf("              |\n");
       printf("              ");
        struct dlist *tr;
    tr=start;
   
    if(start==NULL)
    {
        printf("-->  No Data");
    }
        while (tr!=NULL)
    {
        printf("-->  %d",tr->data);
    tr=tr->next;
    }
       printf("\n\n\n\n\n\n\nPRESS ENTER KEY");
       gets(s);
}
////////////////////////////////////////////////////////////////////////
void insert_first(void)
{
    struct dlist *temp;
    temp=malloc(sizeof(struct dlist));
        printf("\nEnter the data : ");
    scanf("%d",&temp->data);
    temp->next=start;
    start->previous=temp;
    start=temp;


        printf("\nYour Data  Successfully  Saved in First Position");
        printf("\n-----------------------------------\n");
        sleep(2);



}
///////////////////////////////////////////////////////////////////////
void insert_btwn(int x)
{
int i;   
    struct dlist *tr,*temp;
    tr=start;
    for(i=0;i<x-2;i++)
    {
     tr=tr->next;
    }
    temp=malloc(sizeof(struct dlist));
    printf("\nEnter the data : ");
    scanf("%d",&temp->data);
    temp->next=tr->next;
    tr->next=temp;
    temp->previous=tr;
    if(temp->next!=0)
    {temp->next->previous=temp;}


       
        printf("\nYour Data  Successfully Saved in  Position %d ",x);
        printf("\n-----------------------------------\n");
        sleep(2);


}
////////////////////////////////////////////////////////////////////////
void delete(int data)
{
 struct dlist *temp,*tr;
        ////////// if data in  Starting position /////////////
    if(start->data==data)
    {
          if(start->next!=NULL)
            {
         temp=start;
         start=start->next;
         start->previous=NULL;
           free(temp);
          }
    else
        {
                start=NULL;
                }
    printf("\nYour Data %d is  Successfully Deleted ",data);
        printf("\n-----------------------------------\n");
        sleep(2);
     }

        ////////// if middle ////////////////////////////////

    else
    {
    tr=start;
    while(tr->next->next!=NULL)
         {
        if(tr->next->data==data)
         {
         temp=tr->next;
         tr->next=temp->next;
         temp->next->previous=tr;
         free(temp);
         printf("\nYour Data %d is Successfully Deleted",data );
                printf("\n----------------------------------\n");
                sleep(2);
        return ;
         }
        tr=tr->next;
        }
        ///////// Last //////////////////////////////////////      
     if(tr->next->data==data)
        {
        temp=tr->next;
        tr->next=NULL;
        free(temp);
        printf("\nYour Data %d is Successfully Deleted",data);
        printf("\n----------------------------------\n");
        sleep(2);
        }
    else
        {
        printf("\nThis data not exist");
        printf("\n\n\n\n\n\n\n\n\npress any key ");
        gets(s);
        }       
    }
}
//////////////Reverse /////////////////////////////////////////////////
void reverse(void)
{
struct dlist *temp,*tr0,*tr;
temp=malloc(sizeof(struct dlist));
tr=tr0=start;
temp=start->next;
start->next=NULL;
    while(temp!=NULL)
    {
    tr=temp;
    tr0->previous=tr;
    temp=temp->next;
    tr->next=tr0;
    tr->previous=temp;
    tr0=tr;
    }
start=tr;
}
////////////////////////////////////////////////////////////////////////

void sorted_create(void)
{
struct dlist *temp,*tr;
temp=malloc(sizeof(struct dlist));
scanf("%d",&temp->data);
temp->next=NULL;
temp->previous=NULL;
if(start==NULL||start->data>temp->data)
 {
  if(start!=NULL)
    {start->previous=temp;}
   temp->next=start;
   start=temp;
return;
 }
else
{
  tr=start;


while(tr->next!=NULL&&tr->next->data<temp->data)
    {
    tr=tr->next;
    }

temp->previous=tr;
temp->next=tr->next;
tr->next=temp;

 if(temp->next!=NULL)
  {
  temp->next->previous=temp;
  }
}

}

Single Link




   
    ///////   Created   By  ///////////////////////////////
    ///                                                         ///
    ///                                                         ///
    ///     MUHAMMED ISMAIL  PP     ///
    ///                                                        ///
    ///                                                       ///
    /////////////////////////////////////////////////////////////



#include<stdio.h>
#include<stdlib.h>
void create(void);
void sorted_create(void);
void display(void);
void insert_first(void);
void insert_btwn(int x);
void delete(int data);
void reverse(void);
char s[5];    
       struct list
        {
        int data;
    struct list *next;
    }*start=NULL;
///////////////////Main////////////////////////////////////////
int main()
{   
while(1)
{
system("clear");
printf("\n");
printf("                     ---------------Single List Data Structure-------------------- \n\n");
printf("                             1--Create \n\n");
printf("                                 2--view \n\n");
printf("                         3--insert\n\n");
printf("                         4--Delete\n\n");
printf("                             5--Reverse\n\n");
printf("                             6--Exit\n\n");
printf("                 ------------------------------------------------------------- \n\n");
int x;
int i;
printf("Enter choice   :");
    scanf("%d",&x);
switch(x)
    {
     case 1:
     {
    system("clear");
    printf("\nSelect your choice :\n");
    printf("\n--------------------------------------------\n");
    printf("\n        1)---Create Normal Structure :\n");
    printf("\n        2)---Create Sorted Structure :\n");
    printf("\n--------------------------------------------\n");
    scanf("%d",&x);
    switch (x)
    {
        case 1:
         {
        printf("\n\n\nEnter the number of elements  :");
         scanf("%d",&x);
           for(i=0;i<x;i++)
           {
            printf("\nEnter the  data %d = ",i+1);
                    create();
           }
   
        printf("\nYour Data Structure  Successfully Created");
            printf("\n-----------------------------------\n");
               sleep(2);
        break;
          }
        case 2:
        {
         printf("\n\n\nEnter the number of elements  :");
                 scanf("%d",&x);
                   for(i=0;i<x;i++)
                   {
                    printf("\nEnter the  data %d = ",i+1);
                    sorted_create();
                   }

                printf("\nYour Data Structure  Successfully Created");
                printf("\n-----------------------------------\n");
                sleep(2);
                break;
        }
     }
    break;
    }   
      case 2:
    {
    gets(s);
    display();
    break;
    }
      case 3:
    {
    printf("\nEnter the position :");
    scanf("%d",&x);
      if(x==1)
            { insert_first();}
      else
        { insert_btwn(x); }
    break;
        }
      case 4:
    {
     printf("\nEnter the data for delete  : ");
     scanf("%d",&x);
      gets(s);
     delete(x);
     break;
    }   
      case 5:
    {
    reverse();
    break;
    }
      case 6:       
    {
    return;
    break;
    }
      default:
    {
    gets(s);
    printf("\n\nEnter  valid Choice : Press Any Key to Return :  ");
    gets(s);
    break;
    }

}

}
return ;
}
///////////////////////Create//////////////////////////////////
void create(void)
{
   struct list *temp,*tr;
    temp=malloc(sizeof(struct list));
    scanf("%d",&temp->data);
    temp->next=NULL;
   
   
    if(start==NULL)
    {
    start=temp;
    }   
    else
    {
    tr=start;
        while(tr->next !=NULL)
            {
        tr=tr->next;
        }
    
    tr->next=temp;
    }
}
/////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////
void display(void)
{
    char s[5];
       printf("\n\n\n\n\n\n\n\n\n\n\n\n             START\n");   
       printf("              |\n");
       printf("              |\n");
       printf("              |\n");
       printf("              |\n");
       printf("              ");
        struct list *tr;
    tr=start;
   
    if(start==NULL)
        {
        printf("-->  No Data");
        }


    while (tr!=NULL)
    {
       printf("-->  %d",tr->data);
    tr=tr->next;
    }
       printf("\n\n\n\nPRESS ENTER KEY");
       gets(s);
}
////////////////////////////////////////////////////////////////////////
void insert_first(void)
{
    struct list *temp;
    temp=malloc(sizeof(struct list));
        printf("\nEnter the data : ");
    scanf("%d",&temp->data);
    temp->next=start;
    start=temp;

        printf("\nYour Data  Successfully  Saved in First Position");
        printf("\n-----------------------------------\n");
        sleep(2);





}
///////////////////////////////////////////////////////////////////////
void insert_btwn(int x)
{
int i;   
    struct list *tr,*temp;
    tr=start;
    for(i=0;i<x-2;i++)
    {
     tr=tr->next;
    }
    temp=malloc(sizeof(struct list));
    printf("\nEnter the data : ");
    scanf("%d",&temp->data);
    temp->next=tr->next;
    tr->next=temp;

        printf("\nYour Data  Successfully Saved in  Position %d ",x);
        printf("\n-----------------------------------\n");
        sleep(2);

}
////////////////////////////////////////////////////////////////////////
void delete(int data)
{
 struct list *temp,*tr;
        ////////// if data in  Starting position /////////////
    if(start->data==data)
    {
     temp=start;
     start=start->next;
     free(temp);
      
        printf("\nYour Data %d is  Successfully Deleted ",data);
        printf("\n-----------------------------------\n");
        sleep(2);
   


       }

        ////////// if middle ////////////////////////////////

    else
    {
    tr=start;
    while(tr->next->next!=NULL)
         {
        if(tr->next->data==data)
         {
         temp=tr->next;
         tr->next=temp->next;
         free(temp);
       
              printf("\nYour Data %d is  Successfully Deleted ",data);
                printf("\n-----------------------------------\n");
                   sleep(2);


        return ;
         }
        tr=tr->next;
       
        }
        ///////// Last //////////////////////////////////////      
     if(tr->next->data==data)
        {
        temp=tr->next;
        tr->next=NULL;
        free(temp);
       

             printf("\nYour Data %d is  Successfully Deleted ",data);
               printf("\n-----------------------------------\n");
             sleep(2);


         }
    else
        {
        printf("\nThis data not exist");
        printf("\n\n\n\n\n\n\n\n\npress any key ");
        gets(s);
        }       
    }
}
///////////////////Reverse /////////////////////////////////////////////////
void reverse(void)
{
struct list *temp,*tr,*tr0;

tr=tr0=start;
temp=start->next;
start->next=NULL;

while(temp!=NULL)
{
tr=temp;
temp=temp->next;
tr->next=tr0;
tr0=tr;
}
start=tr;



        printf("\nYour Data  is  Reversed in Position  ");
        printf("\n-----------------------------------\n");
        sleep(2);


}

/////////////////////////////////////////////////////////////////////////

void sorted_create(void)
{
struct list *temp,*tr;
temp=malloc(sizeof(struct list));
scanf("%d",&temp->data);
temp->next=NULL;
if(start==NULL||start->data>temp->data)
 {
 temp->next=start;
 start=temp;
 return;
 }
else
 {
 tr=start;
 }

while(tr->next!=NULL&&tr->next->data<temp->data)
    {
    tr=tr->next;
    }

temp->next=tr->next;
tr->next=temp;
}

Monday, 3 October 2011

Universal IR Txr / Rxr For Any Device



1--    Here am designed a Transmitter and Receiver. Which will receive the key code as per the           
          picture given bellow.


       .
       In this first two bits in key 1 are high for 1ms and low for 5ms, this can be identify the receiver
     which detect a new signal . Next  six (1ms high and 2ms low)bits, thats are d0  to  d5,you can give
     this as different values for different keys as per your requirement.After 100ms code will repeat.

2--Transmitter and Reciever circuit Diagram
                                                                  TXr  circuit


                                                                  Rxr  Circuit


  3--Program for Transmitter and Receiver
     
       This program is compiled with Wiz_C compiler


--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Txr
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
#include<stdio.h>
#include<pic.h>
#include<PortBits.h>
#include<delays.h>
unsigned int checktime=0;
bit var1=0,var2=0,var3=0,var4=0,var5=0,var6=0;       
void main()
{
ANSEL=0;
CMCON=7;
TRISA=0b111110;
TRISC=0b111111;
PORTA=PORTC=0;
/////////////////////////////////////////////////////
Wait(1000);
for(;;)
{
Wait(100);
if(bRA1==1||bRA2==1||bRC0==1||bRC1==1)
{
var1=1;var2=1;var3=bRC1^1;var4=bRC0^1;var5=bRA2^1;var6=1;
///////starting bit
bRA0=1;
Wait(1);
bRA0=0;
Wait(5);


bRA0=1;
Wait(1);
bRA0=0;
Wait(5);
}
//////////Data bit///////////////////////////
bRA0=var1;
Wait(1);
bRA0=0;
Wait(2);


bRA0=var2;
Wait(1);
bRA0=0;
Wait(2);


bRA0=var3;
Wait(1);
bRA0=0;
Wait(2);


bRA0=var4;
Wait(1);
bRA0=0;
Wait(2);


bRA0=var5;
Wait(1);
bRA0=0;
Wait(2);


bRA0=var6;
Wait(1);
bRA0=0;
Wait(2);


//////////////////////////////
var1=var2=var3=var4=var5=var6=0;
}
}
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Txr  Hex  file
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
:020000040000FA
:1000000000005F30A6000428263084003830A400A9
:10001000840A8001A40B08280D281F2826078400C5
:10002000122884000008A000840A0008A10008002B
:10003000A00026088400A603200880000800830191
:100040008A118312BA01BB018312B8108312B8114E
:100050008312B8128312B8138312B9108312B91124
:1000600083018A014C288A1101300E20840A8A11EA
:100070003B208A01080020082104031908000130F0
:10008000F920000000005430F5208A110A12A00364
:10009000200F3B28A1033B288316910183120730D0
:1000A000990083163E3085003F3087008312870118
:1000B000850103301820E830182033200230A607CD
:1000C000003018206430182033200230A607003991
:1000D0008518013EFF3E03197F2800390519013EAE
:1000E000FF3E03197F2800390718013EFF3E031920
:1000F0007F2800398718013EFF3E031DA028B81451
:10010000B81500398718013E013A0038B812031DAE
:10011000B81600390718013E013A0038B813031D1C
:10012000B81700390519013E013A0038B910031D0E
:10013000B914B91505140030C32005140030C320CC
:100140000039B818013E0510031D05140030D220F7
:100150000039B819013EE120B81A013EE120B81B70
:10016000013EE120B918013EE120B919013E051018
:10017000031D05140030D220B911B910B813B812FC
:10018000B811B81060281820013018203320023030
:10019000A607051000301820053018203320023043
:1001A000A607080018200130182033200230A607C7
:1001B0000510003018200230182033200230A60726
:1001C00008000510031D0514003018200130182008
:1001D00033200230A6070510003018200230182006
:1001E00033200230A60700390800A200A20BF6282F
:0E01F0000800A300F030F520A30BFA28080049
:10420000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBE
:10421000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAE
:10422000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9E
:10423000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8E
:10424000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7E
:10425000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6E
:10426000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5E
:10427000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4E
:04400E000430FFFF7C
:00000001FF

-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Rxr
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

#include<stdio.h>
#include<pic.h>
#include<PortBits.h>
#include<delays.h>
unsigned int checktime=0;
bit var1=0,var2=0,var3=0,var4=0,var5=0,var6=0;       

void main()
{
ANSEL=0;
CMCON=7;
TRISA=1;
TRISC=0;
PORTA=PORTC=0;
/////////////////////////////////////////////////////
for(;;)
{
if(bRA0==1)
{
  Wait(1);
  Wait(.005);
  Wait(.005);
  Wait(.005);
  Wait(.005);
  Wait(.005);
  Wait(.005);
   if(bRA0==0)
     {
      Wait(5);
      if(bRA0==1)    
      {
        Wait(1); 
        if(bRA0==0)
          {
           Wait(5);
         ///////////  
            if(bRA0==1)
            {var1=1;}
            else
            {var1=0;} 
       Wait(3);
            if(bRA0==1)
            {var2=1;}
            else
            {var2=0;} 
       Wait(3); 
            if(bRA0==1)
            {var3=1;}
            else
            {var3=0;} 
       Wait(3);
            if(bRA0==1)
            {var4=1;}
            else
            {var4=0;} 
       Wait(3);
            if(bRA0==1)
            {var5=1;}
            else
            {var5=0;} 
       Wait(3);
            if(bRA0==1)
            {var6=1;}
            else
            {var6=0;} 
       
       ///////////////
Wait(500);    
   }
  }
}
}
if(var1==1&&var2==1&&var3==1&&var4==1&&var5==1&&var6==1)
{bRA1=bRA1^1;Wait(10);}

if(var1==1&&var2==1&&var3==1&&var4==1&&var5==0&&var6==1)
{bRA2=bRA2^1;Wait(10);}

if(var1==1&&var2==1&&var3==1&&var4==0&&var5==1&&var6==1)
{bRC0=bRC0^1;Wait(10);}

if(var1==1&&var2==1&&var3==0&&var4==1&&var5==1&&var6==1)
{bRC1=bRC1^1;Wait(10);}


var1=0;var2=0;var3=0;var4=0;var5=0;var6=0;
}}
///////////////////////////////////////////////////////
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Rxr  Hex file
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
:020000040000FA
:1000000000005F30A6000428263084003830A400A9
:10001000840A8001A40B08280D281F2826078400C5
:10002000122884000008A000840A0008A10008002B
:10003000A00026088400A603200880000800830191
:100040008A118312BA01BB018312B8108312B8114E
:100050008312B8128312B8138312B9108312B91124
:1000600083018A0133288316910183120730990096
:1000700083160130850087018312870185010039CD
:100080000518013EFF3E031D852800301820013071
:1000900018205F214A214A212221031D852832216F
:1000A000031D852800301820013018205F212221EF
:1000B000031D85283221031D5F28B8146028B8105D
:1000C0003E21031D6528B8156628B8113E21031D81
:1000D0006B28B8166C28B8123E21031D7128B8177A
:1000E0007228B8133E21031D7728B9147828B91057
:1000F0003E21031D7D28B9157E28B9110130182035
:10010000F43018205F210230A6070421031DA02827
:100110001321031DA0281D21031DA0280921031D53
:10012000A0281821031DA0280E21031DA028003996
:100130008518013E013A00388510031D85142A21D7
:100140000421031DBF281321031DBF281D21031DEA
:10015000BF280921031DBF280039B918013E031427
:100160000038031DBF280E21031DBF2800390519C3
:10017000013E013A00380511031D05152A2104210D
:10018000031DDE281321031DDE281D21031DDE288B
:100190000039B81B013E03140038031DDE28182166
:1001A000031DDE280E21031DDE2800390718013E3D
:1001B000013A00380710031D07142A210421031DEA
:1001C000FD281321031DFD280039B81A013E031430
:1001D0000038031DFD280921031DFD281821031DDA
:1001E000FD280E21031DFD2800398718013E013A24
:1001F00000388710031D87142A21B810B811B812CF
:10020000B813B910B9113F280039B818013EFF3EA4
:1002100008000039B81B013EFF3E08000039B9193B
:10022000013EFF3E08000039B819013EFF3E0800BC
:100230000039B918013EFF3E08000039B81A013EE6
:10024000FF3E08000230A60700390518013E0314DE
:1002500000380800003018200A3018205F210230D2
:10026000A607080000301820053018205F21023052
:10027000A60700390518013EFF3E0800003018208F
:10028000033018205F210230A60700390518013E0F
:10029000FF3E08000230A60700301820003018206A
:1002A0005F210230A60700301820003018205F219F
:1002B0000230A60700301820003018205F298A116C
:1002C00001300E20840A8A1167218A010800200863
:1002D00021040319080001307C2100000000543083
:1002E00078218A110A12A003200F6729A103672928
:1002F000A200A20B79290800A300F0307821A30BFB
:040300007D2908004B
:10420000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFBE
:10421000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFAE
:10422000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF9E
:10423000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF8E
:10424000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF7E
:10425000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF6E
:10426000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5E
:10427000FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF4E
:04400E000430FFFF7C
:00000001FF
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------



       if you haven't Wiz_c compiler then copy Hex file of Txr and paste to notepad and save as Txr.hex.
     similarly in Rxr. Burn this two file into PIC16f676 one for Rxr other for Txr.  

Simple Working
 
           After completion of hardware please press key 1, then Txr will produce corresponding IR code
     as per the above picture ,which will transmit through the photo diode.IR photo detector will receive
     this IR signal and produce negative out put.Which will be converted to positive through BC557 and
     given to pic. which will decode the code and ON corresponding output pin (pin 13--A1).If same
     key press again output will off(toggle).similarly you can control 4 different switches Independently. 

         You can increase the number of keys by just giving more keys into all pins of Txr.And change
     d0- -d6 values for each keys as your own way.Design corresponding Rxr code.

4--Proteus Simulation file is included with dowloading pack
  •   To Download complete file related to this project Click here               


   If you have remote hand set of any company then you need only design the reciever circuit corresponding to that remote transmitter, to know about that please  click here
 (Don't  forget write the comments about this project)