Monday, 24 October 2011

Idea about "Change"....

Change is inspiring.
The best change often starts as one simple thought.

Change is positive.
It brings an enduring transformation.

Change is inevitable.
The sooner we open up to it, the better.

Change is essence of life.
If we don't change, we don't grow.

change is future.
And it is here right now.

Be the change you want to see!

Wednesday, 19 October 2011

"C program for Student Database from linked list"

/*PROBLEM DEFINATION : Implement the Mini Project of Student Database using Linked list for following requirements:
    a. Creation of Student Database in memory containing student ID, Name, Name
        Initials, Address, Contact No and Date of Birth .
    b. Insertion, Deletion, Modification of student record for a given student ID.
    c. Sorting on name initials and searching a particular student record on name initials
  */

#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
#include<string.h>
#include<dos.h>

struct stud
{
 int rn,id,ph;
 char add[30],na[20],d[15],in[5];
 struct stud *next;
}*h=NULL,*p,*q,*t;

void add()
{
  clrscr();
  p =(stud *)malloc(sizeof(stud));
  printf("\nEnter the Initials of Student : ");
  scanf("%s",&p->in);
  printf("\nEnter the Last Name of Student : ");
  scanf("%s",&p->na);
  printf("\nEnter the ID of Student : ");
  scanf("%d",&p->id);
  printf("\nEnter the Roll No. of Student : ");
  scanf("%d",&p->rn);
  printf("\nEnter the Ph No. of Student : ");
  scanf("%d",&p->ph);
  printf("\nEnter the Address of Student : ");
  scanf("%s",&p->add);
  printf("\nEnter the D.O.B. of Student(dd/mm/yyyy) : ");
  scanf("%s",&p->d);

  p->next=NULL;

  if(h==NULL)
  {
   h=p;
  }
  else
  {
    q=h;
    while(q->next!=NULL)
    q=q->next;
    q->next=p;
  }
  ts++;
}

void addAt(int r)
{
 q=h;
 while(q->rn!=r || q==NULL)
  q=q->next;
 if(q->rn==r)
 {
  clrscr();
  p =(stud *)malloc(sizeof(stud));
  printf("\nEnter the Initials of Student : ");
  scanf("%s",&p->in);
  printf("\nEnter the Last Name of Student : ");
  scanf("%s",&p->na);
  printf("\nEnter the ID of Student : ");
  scanf("%d",&p->id);
  printf("\nEnter the Roll No. of Student : ");
  scanf("%d",&p->rn);
  printf("\nEnter the Ph No. of Student : ");
  scanf("%d",&p->ph);
  printf("\nEnter the Address of Student : ");
  scanf("%s",&p->add);
  printf("\nEnter the D.O.B. of Student(dd/mm/yyyy) : ");
  scanf("%s",&p->d);
  p->next=q->next;
  q->next=p;
  ts++;
 }
 else
 {
  printf("\n\nRecord Not Found.");
 }
}


void delAt(int r)
{
 q=h;
 while((q->next)->rn!=r || q==NULL)
  q=q->next;
 if((q->next)->rn==r)
 {
  q->next=(q->next)->next;
  printf("\n\nRecord Deleted.");
  ts--;
 }
 else
  printf("\n\nRecord Not Found.");
}

void modAt(int id)
{
 q=h;
 int ch;
 while(q->id!=id && q!=NULL)
  q=q->next;
 if(q->id==id)
 {
  clrscr();
  printf("******* MODIFY *******\n1.Name Initials\n2.Last Name");
  printf("\n3.Roll No.\n4.Phone\n5.Add\n6.D.O.B.:\nEnter choice: ");
  scanf("%d",&ch);
  switch(ch)
  {
  case 1 :  printf("\n\nEnter the Initials of Student : ");
          scanf("%s",&q->in);break;
  case 2 :  printf("\nEnter the Last Name of Student : ");
          scanf("%s",&q->na);break;
  case 3 :  printf("\nEnter the Roll No. of Student : ");
          scanf("%d",&q->rn);break;
  case 4 :  printf("\nEnter the Ph No. of Student : ");
          scanf("%d",&q->ph);break;
  case 5 :  printf("\nEnter the Address of Student : ");
          scanf("%s",&q->add);break;
  case 6 :  printf("\nEnter the D.O.B. of Student(dd/mm/yyyy) : ");
          scanf("%s",&q->d);break;
  }
 }
 else
  printf("\nRecord not Found.");
}

void search(char ni[5])
{
 int flag=0;
 q=h;
 clrscr();
 while(q!=NULL)
 {
  if(stricmp(q->in,ni)==0)
  {
  flag=1;
  printf("\n\nInitals of Student :   %s ",q->in);
  printf("\n\nLast Name of Student : %s ",q->na);
  printf("\n\nID of Student :        %d ",q->id);
  printf("\n\nRoll No. of Student :  %d",q->rn);
  printf("\n\nPh No. of Student :    %d",q->ph);
  printf("\n\nAddress of Student :   %s",q->add);
  printf("\n\nD.O.B. of Student :    %s",q->d);
  printf("\n\n\n");
  }
  q=q->next;
 }
 if(flag==0)
  printf("\n\nNo Match Found.");
}

void sort()
{
 p=h;
 while(p!=NULL)
 {
  q=h;
  while(q!=NULL)
  {
   if(stricmp(q->in,(q->next)->in)>0)
   {
    strcpy(t->in,q->in);
    strcpy(t->na,q->na);
    t->id=q->id;
    t->rn=q->rn;
    t->ph=q->ph;
    strcpy(t->add,q->add);
    strcpy(t->d,q->d);


    strcpy(q->in,(q->next)->in);
    strcpy(q->na,(q->next)->na);
    q->id=  (q->next)->id;
    q->rn=  (q->next)->rn;
    q->ph=  (q->next)->ph;
    strcpy(q->add,(q->next)->add);
    strcpy(q->d,(q->next)->d);

    strcpy((q->next)->in,t->in);
    strcpy((q->next)->na,t->na);
    (q->next)->id = t->id;
    (q->next)->rn = t->rn;
    (q->next)->ph = t->ph;
    strcpy((q->next)->add,t->add);
    strcpy((q->next)->d,t->d);

   }
   q=q->next;
  }
  p=p->next;
 }

}

void disp()
{
 p=h;
 clrscr();
 while(p!=NULL)
 {
  printf("\nInitals of Student :   %s ",p->in);
  printf("\nName of Student :      %s ",p->na);
  printf("\nID of Student :        %d ",p->id);
  printf("\nRoll No. of Student :  %d",p->rn);
  printf("\nPh No. of Student :    %d",p->ph);
  printf("\nAddress of Student :   %s",p->add);
  printf("\nD.O.B. of Student :    %s",p->d);
  printf("\n\n");
  p=p->next;
 }
}

void main()
{
 int ch=0,r;
 char ni[5];
 clrscr();
 while(ch!=8)
 {
  clrscr();
  printf("1.Add the Record.\n\n2.Add Record at Locn.\n\n3.Delete Record.");
  printf("\n\n4.Modify Record.\n\n5.Search Record.\n\n6.Sort Records.");
  printf("\n\n7.Display\n\n8.Exit");
  printf("\n\nEnter the Choice: ");
  scanf("%d",&ch);
   switch(ch)
   {
    case 1:
    add();
    break;

    case 2:
    printf("\nEnter the Roll No. : ");
    scanf("%d",&r);
    addAt(r);
    break;

    case 3:
    printf("\nEnter the Roll No. : ");
    scanf("%d",&r);
    delAt(r);
    break;

    case 4:
    printf("\nEnter the ID : ");
    scanf("%d",&r);
    modAt(r);
    break;

    case 5:
    printf("\nEnter the Initials : ");
    scanf("%s",&ni);
    search(ni);
    break;

    case 6:
    sort();
    printf("\n\nSorted");
    break;
    case 7:
    disp();
    break;
   }
 getch();
 }
 getch();
}
*/
OUTPUT :
==========

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 1
Enter the Initials of Student : T.T.
Enter the Last Name of Student : MOJAD
Enter the ID of Student : 001
Enter the Roll No. of Student : 1
Enter the Ph No. of Student : 1234
Enter the Address of Student : qwer
Enter the D.O.B. of Student(dd/mm/yyyy) :10/12/1988

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 7
Initals of Student :   T.T.
Name of Student :      MOJAD
ID of Student :        1
Roll No. of Student :  1
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1988

Initals of Student :   A.M.
Name of Student :      Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    12345
Address of Student :   abde
D.O.B. of Student :    10/12/1990

Initals of Student :   S.M.
Name of Student :      Mane
ID of Student :        3
Roll No. of Student :  3
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    12/12/1989

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 2
Enter the Roll No. : 2
Enter the Initials of Student : Z.Z.
Enter the Last Name of Student : Shaikh
Enter the ID of Student : 005
Enter the Roll No. of Student : 4
Enter the Ph No. of Student : 1234
Enter the Address of Student : qwer
Enter the D.O.B. of Student(dd/mm/yyyy) : 14/3/1991

Initals of Student :   T.T.
Name of Student :      MOJAD
ID of Student :        1
Roll No. of Student :  1
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1988

Initals of Student :   A.M.
Name of Student :      Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1990

Initals of Student :   Z.Z.
Name of Student :      Shaikh
ID of Student :        5
Roll No. of Student :  4
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :   14/3/1991

Initals of Student :   S.M.
Name of Student :      Mane
ID of Student :        3
Roll No. of Student :  3
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    12/12/1989

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 5
Enter the Initials : a.m.

Initals of Student :   A.M.
Last Name of Student : Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1990

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 4
Enter the ID : 001

******* MODIFY *******
1.Name Initials
2.Last Name
3.Roll No.
4.Phone
5.Add
6.D.O.B.:
Enter choice: 1

Enter the Initials of Student : T.D.

Initals of Student :   T.D.
Name of Student :      MOJAD
ID of Student :        1
Roll No. of Student :  1
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1988

Initals of Student :   A.M.
Name of Student :      Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1990

Initals of Student :   Z.Z.
Name of Student :      Shaikh
ID of Student :        5
Roll No. of Student :  4
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    14/3/1991

Initals of Student :   S.M.
Name of Student :      Mane
ID of Student :        3
Roll No. of Student :  3
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    12/12/1989

1.Add the Record.
2.Add Record at Locn.
3.Delete Record.
4.Modify Record.
5.Search Record.
6.Sort Records.
7.Display
8.Exit

Enter the Choice: 6
Sorted
Initals of Student :   A.M.
Name of Student :      Mehata
ID of Student :        2
Roll No. of Student :  2
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1990

Initals of Student :   S.M.
Name of Student :      Mane
ID of Student :        3
Roll No. of Student :  3
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    12/12/1989

Initals of Student :   T.D.
Name of Student :      MOJAD
ID of Student :        1
Roll No. of Student :  1
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    10/12/1988

Initals of Student :   Z.Z.
Name of Student :      Shaikh
ID of Student :        5
Roll No. of Student :  4
Ph No. of Student :    1234
Address of Student :   qwer
D.O.B. of Student :    14/3/1991
*/

"C program for Circular queue"

/* Program for showing various operations on a Circular queue  represented
   using linked list.
   */

#include<stdio.h>
#include<conio.h>
typedef struct node
 {
   int data;
   struct node *next;
 }node;
void init(node **R);
void enqueue(node **R,int x);
int dequeue(node **R);
int empty(node *rear);
void print(node *rear);
int front_element(node *rear);
int rear_element(node *rear);
void main()
{
 int x,option;
 int n = 0,i;
 node *rear;
 init(&rear);
 clrscr();
 do
   {
      printf("\n1]Insert\t2]Delete\t3]Print");
      printf("\t4]Front element\t5]Rear Element\t6]Quit");
      printf("\nEnter your option:  ");
      scanf("%d",&option);
      switch(option)
      {
        case 1: printf("\nEnter queue data : ");
            scanf("\n %d",&x);
            enqueue(&rear,x);
            break;
        case 2 : if(! empty(rear))
            {
              x=dequeue(&rear);
              printf("\n Element deleted = %d",x);
            }
             else
              printf("\n Uderflow..... Cannot deleted");
             break;
        case 3 : print(rear);
             break;
        case 4 :if(!empty(rear))
               printf("\nFront Element = %d",front_element(rear));
            else
               printf("\nQueue is empty");
            break;
        case 5 :if(!empty(rear))
               printf("\nRear Element = %d",rear_element(rear));
            else
               printf("\nQueue is empty");
            break;
     }
  }while(option != 6);

 }

 void init(node **R)
    {
      *R = NULL;
    }

 void enqueue(node **R,int x)
    {
     node *p;
     p = (node *)malloc(sizeof(node));
     p->data = x;
     if(empty(*R))
    {
      p->next = p;
      *R = p;
    }
     else
       {
      p->next = (*R)->next;
      (*R)->next = p;
      (*R) = p;
       }
    }

int dequeue(node **R)
  {
    int x;
    node *p;
    p=(*R)->next;
    x=p->data;
    if(p->next == p)
     {
         *R = NULL;
         free(p);
         return(x);
     }
   (*R)->next = p->next;
   free(p);
   return(x);
 }

void print(node *rear)
  {
   node *p;
   if(!empty(rear))
      {
      p = rear->next;
      }
   else
     {
       printf("\nQueue is empty");
       return;
     }

   printf("\n");
   do
     {
    printf("%d  ",p->data);
    p = p->next;
     }while(p != rear->next);
  }

int empty(node *P)
  {
    if(P->next== NULL)
        return(1);
    return(0);
  }

int front_element(node *rear)
  {
     return(rear->next->data);
  }

int rear_element(node *rear)
  {
     return(rear->data);
  }
  /*
  OUTPUT:-

1]Insert        2]Delete        3]Print 4]Front element 5]Rear Element  6]Quit 
Enter your option:  1                                                          
                                                                               
Enter queue data : 23                                                          
                                                                               
1]Insert        2]Delete        3]Print 4]Front element 5]Rear Element  6]Quit 
Enter your option:  1                                                          
                                                                               
Enter queue data : 34                                                          
                                                                               
1]Insert        2]Delete        3]Print 4]Front element 5]Rear Element  6]Quit 
Enter your option:  1                                                          
                                                                               
Enter queue data : 45                                                          
                                                                               
1]Insert        2]Delete        3]Print 4]Front element 5]Rear Element  6]Quit 
Enter your option:  3                                                          
                                                                               
23  34  45                                                                     
1]Insert        2]Delete        3]Print 4]Front element 5]Rear Element  6]Quit 
Enter your option:  4                                                          
                                                                               
Front Element = 23                                                             
1]Insert        2]Delete        3]Print 4]Front element 5]Rear Element  6]Quit 
Enter your option:  5                                                          
                                                                               
Rear Element = 45                                                              
1]Insert        2]Delete        3]Print 4]Front element 5]Rear Element  6]Quit 
Enter your option:  2                                                          
                                                                               
 Element deleted = 23                                                          
1]Insert        2]Delete        3]Print 4]Front element 5]Rear Element  6]Quit 
Enter your option:  6
*/
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               

"C program for Stack as ADT"

/*  IMPLEMENT STACK AS AN ADT USING ARRAY. USE THIS ADT TO
        PERFORM EXPRESSION CONVERSION & EVALUATION (INFIX TO
        POSTFIX,INFIX TO PREFIX,PREFIX TO INFIX,PREFIX TO POSTFIX,
        POSTFIX TO INFIX & POSTFIX TO PREFIX)
   */ .


  #include<stdio.h>
  #include<conio.h>
  #include<ctype.h>
  #include<string.h>
  #define MAX 20
  void in2post();
  void in2pre();
  void post2in();
  void pre2in();
  void post2pre();

  char s[MAX];
  char s1[MAX][MAX];
  int top=-1;
  void main()
   {
    char e[MAX];
    int choice;
    char ch;
    do
    {
     clrscr();
     printf("\n\n\t================= GIVEN MENU FOR STACK=================");
     printf("\n\n\t 1.Infix to Postfix");
     printf("\n\n\t 2.Infix to Prefix");
     printf("\n\n\t 3.Postfix to Infix");
     printf("\n\n\t 4.Prefix to Infix");
     printf("\n\n\t 5.Postfix to Prefix");
     printf("\n\n\t 6.EXIT");
     printf("\n\n\t Enter the Choice(1,2,3,4,5,6): ");
     scanf("%d",&choice);
     printf("\n\n\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
     switch(choice)
      {
    case 1:
           printf("\n\n\t*** INFIX TO POSTFIX ***");
           printf("\n\n\t Enter the Infix Exp: ");
           scanf("%s",&e);
           in2post(e);
           break;

    case 2:
           printf("\n\n\t*** INFIX TO PREFIX ***");
           printf("\n\n\t Enter the Infix Exp: ");
           scanf("%s",&e);
           in2pre(e);
           break;

    case 3:
           printf("\n\n\t*** POSTFIX TO INFIX ***");
           printf("\n\n\t Enter the Postfix Exp: ");
           scanf("%s",&e);
           post2in(e);
           break;

    case 4:
           printf("\n\n\t*** PREFIX TO INFIX ***");
           printf("\n\n\t Enter the Prefix Exp: ");
           scanf("%s",&e);
           pre2in(e);
           break;

    case 5:
           printf("\n\n\t*** POSTFIX TO PREFIX ***");
           printf("\n\n\t Enter the Postfix Exp: ");
           scanf("%s",&e);
           post2pre(e);
           break;

    case 6:
           exit(0);
           break;

    default:
        printf("\n\n\t*** INVALID CHOICE ***");
      }
      printf("\n\n\t^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^");
      printf("\n\n\t Do you want to continue(y/n): ");
      ch=getche();
    }while(ch=='Y'||ch=='y');
    getch();
   }


  void push(char c)
   {
    if(top>=MAX-1)
     {
       printf("\n\n\T Stack is Full...");
       return ;
     }
    else
     {
      top++;
      s[top]=c;
     }
   }

  char pop()
   {
     char c;
     if(top<0)
      {
    return NULL;
      }
     else
      {
    c=s[top];
    top--;
    return(c);
      }
   }

  int prior(char c)
   {
     if(c=='$'||c=='^')
     return 3;
     if(c=='*'||c=='/'||c=='%')
     return 2 ;
     else
      {
       if(c=='+'||c=='-')
       return 1 ;
       else
       return 0 ;
      }
   }

  void in2post(char e[MAX])
   {
    int i=0,p=0;
    char pe[MAX],c,opr;
    while(e[i]!='\0')
     {
      c=e[i];
      if(isalpha(c))
      pe[p++]=c;
      if(c=='(')
      push(c);
      if(c=='*'||c=='/'||c=='+'||c=='-'||c=='%'||c=='$'||c=='^')
       {
    if(top!=-1)
     {
      opr=pop();
      while(prior(opr)>=prior(c))
       {
         pe[p++]=opr;
         opr=pop();
       }
      push(opr);
      push(c);
     }
    else
     push(c);
       }
      if(c==')')
       {
    opr=pop();
    while(opr!='(')
     {
      pe[p++]=opr;
      opr=pop();
     }
       }
      i++;
      }
      while(top!=-1)
      pe[p++]=pop();;
      pe[p++]='\0';
      printf("\n\n\t %s",pe);
   }


  void in2pre(char e[])
   {
    char pe[MAX],c,opr;
    int i=0,p=0;
    strrev(e);
    while(e[i]!='\0')
     {
      c=e[i];
      if(isalpha(c))
      pe[p++]=c;
      if(c==')')
      push(c);
      if(c=='*'||c=='/'||c=='+'||c=='-'||c=='%'||c=='$'||c=='^')
       {
    if(top!=-1)
     {
      opr=pop();
      while(prior(opr)>prior(c))
       {
        pe[p++]=opr;
        opr=pop();
       }
      push(opr);
      push(c);
     }
    else
    push(c);
       }
      if(c=='(')
       {
    opr=pop();
    while(opr!=')')
     {
      pe[p++]=opr;
      opr=pop();
     }
       }
       i++;
      }
      while(top!=-1)
      pe[p++]=pop();
      pe[p++]='\0';
      strrev(pe);
      printf("\n\n\t Prefix Exp is: %s",pe);
    }


  void post2in(char post[])
   {
    char in[20],p1[20],p2[20],ch,o,t[10];
    int i=0;
    while(post[i]!='\0')
     {
      ch=post[i];
      if(isalpha(ch))
       {
     t[0]=ch;
     t[1]='\0';
     top++;
     strcpy(s1[top],t);
       }
      if(ch=='*'||ch=='^'||ch=='+'||ch=='-'||ch=='/')
       {
     strcpy(p2,s1[top]);
     top--;
     strcpy(p1,s1[top]);
     top--;
     t[0]=ch;
     t[1]='\0';
     strcat(p1,t);
     strcat(p1,p2);
     top++;
     strcpy(s1[top],p1);
       }
       i++;
     }

    strcpy(in,s1[top]);
    printf("\n\n\t Infix Exp is: %s",in);
   }

  void pre2in(char pre[])
   {
    char in[MAX],p1[MAX],p2[MAX],ch,o,t[10];
    int i=0;
    strrev(pre);
    while(pre[i]!='\0')
     {
      ch=pre[i];
      if(isalpha(ch))
       {
     t[0]=ch;
     t[1]='\0';
     top++;
     strcpy(s1[top],t);
       }
      if(ch=='*'||ch=='^'||ch=='+'||ch=='-'||ch=='/')
       {
     strcpy(p2,s1[top]);
     top--;
     strcpy(p1,s1[top]);
     top--;
     t[0]=ch;
     t[1]='\0';
     strcat(p1,t);
     strcat(p1,p2);
     top++;
     strcpy(s1[top],p1);
       }
       i++;
     }
    strcpy(in,s1[top]);
    strrev(in);
    printf("\n\n\t Infix Exp is: %s",in);
   }


  void post2pre(char post[])
   {
    char in[MAX],p1[20],p2[20],ch,o,t[10];
    int i=0;
    while(post[i]!='\0')
     {
      ch=post[i];
      if(isalpha(ch))
       {
    t[0]=ch;
    t[1]='\0';
    top++;
    strcpy(s1[top],t);
       }
      if(ch=='*'||ch=='^'||ch=='+'||ch=='-'||ch=='/')
       {
    strcpy(p2,s1[top]);
    top--;
    strcpy(p1,s1[top]);
    top--;
    t[0]=ch;
    t[1]='\0';
    strcat(t,p1);
    strcat(t,p2);
    top++;
    strcpy(s1[top],t);
       }
       i++;
     }
     strcpy(in,s1[top]);
     printf("\n\n\t Prefix Exp is: %s",in);

   }

/*
OUTPUT:-


         GIVEN MENU FOR STACK
 1.Infix to Postfix      2.Infix to Prefix       3.Postfix to Infix      4.Prefi
x to Infix       5.Postfix to Prefix     6.EXIT
        Enter the Choice(1,2,3,4,5,6): 1

 INFIX TO POSTFIX
 Enter the Infix Exp: a+b*c


         abc*+



      
        Enter the Choice(1,2,3,4,5,6): 2

INFIX TO PREFIX
 Enter the Infix Exp: a+c*b/d

Prefix Exp is: +a/*cbd
 Do you want to continue(y/n):y


        Enter the Choice(1,2,3,4,5,6): 3

 POSTFIX TO INFIX
 Enter the Postfix Exp: a+*c/b-d

 Infix Exp is: d
 Do you want to continue(y/n):y


        Enter the Choice(1,2,3,4,5,6): 4

 PREFIX TO INFIX
 Enter the Prefix Exp: a?b+c*d

 Infix Exp is: a
 Do you want to continue(y/n):y


        
        Enter the Choice(1,2,3,4,5,6):5

POSTFIX TO PREFIX
 Enter the Postfix Exp: a^b+c-d/e

 Prefix Exp is: e
 Do you want to continue(y/n):y

*/






























































































































































"C program for polynomial using Linked list"

/*Title :-Represent a Polynomal using a circular linked list and write menu driven program to
  perform addition,multiplication and evaluation.

  */


#include <stdio.h>
#include <conio.h>
#include <math.h>

typedef struct  node
 { int power;
   float coeff;
   struct node *next;
 }node;

      node *  insert(node *head,int power1,float coeff1);
      node *  create();
      node *  padd(node *p1,node *p2);
      node *  pmul(node *p1,node *p2);
      float eval(node *p1,float x);
      void print(node *head);


node *insert(node *head,int power1,float coeff1)
      {  node *p,*q;
     /*terms are store in increasing order of power*/
     /*pointer is used to locate the correct place of insertion.
       pointer p is used to store the address of the node created for
       the current term.If a term with same power is found,coefficients
       are added*/
       p=(node*) malloc(sizeof(node));
       p->power=power1;
       p->coeff=coeff1;
       p->next=NULL;
       if(head==NULL)
     {
          head=p;
          head->next=head;
          return(head);
     }
       if(power1>head->power)
      {
          p->next=head->next;
          head->next=p;
          head=p;
          return(head);
      }
       if(power1==head->power)
      {
          head->coeff=head->coeff+coeff1;
          return(head);
      }

     q=head;
     while(q->next!=head && power1>=q->next->power)
           q=q->next;
     if(p->power==q->power)
           q->coeff=q->coeff+coeff1;
     else
       {
           p->next=q->next;
           q->next=p;
       }
    return(head);
  }


 node *create()
   {
       int n,i,power1;
       float coeff1;
       node *head=NULL;
       printf("\nEnter No. of Terms:");
       scanf("%d",&n);
       printf("\nenter a term as a tuple of (power,coefficient) : ");
       for(i=1;i<=n;i++)
     {   scanf("%d%f",&power1,&coeff1);
         head=insert(head,power1,coeff1);
     }
       return(head);
  }

 node * padd(node *p1,node *p2)
 {   node *p;
     node *head=NULL;
     int power;float coeff;
     p=p1->next;
     do
     {
         head=insert(head,p->power,p->coeff);
         p=p->next;
     } while(p!=p1->next);
     p=p2->next;
     do
     {
         head=insert(head,p->power,p->coeff);
         p=p->next;
     } while(p!=p2->next);
     return(head);
  }

 node *pmul(node *p1,node *p2)
 {   node *head1,*head2;
     node *head=NULL;
     head2=p2->next;
      do
       {  head1=p1->next;
      do
        {
 //    for(p=head1;p!=NULL;p=p->next)
         head=insert(head,head1->power+head2->power,head1->coeff * head2->coeff);
         head1=head1->next;
       }while(head1!=p1->next);
    head2=head2->next;
       }while(head2!=p2->next);
     return(head);
 }

 float eval(node *head,float x)
 {  float value=0.00;
    node *p;
    p=head->next;
    do
       {  value=value+p->coeff * pow(x,p->power);
      p=p->next;
       }while(p!=head->next);
    return(value);
 }

 void print( node *head)
 {  node *p;
    p=head->next;
    printf("\n");
    do
     {
    printf("%6.2fx^%d   ",p->coeff,p->power);
    p=p->next;
     }while(p!=head->next);
 }


 void main()
 { node *p1,*p2,*p3;
   int op;
   float value,x;
   p1=p2=p3=NULL;
   clrscr();
   do
     { printf("\n1)Create first polynomial");
       printf("\n2)Create second polynomial");
       printf("\n3)Print first polynomial");
       printf("\n4)Print second polynomial");
       printf("\n5)Add\n6)Multiply\n7)Evaluate First Polynomial\n8)Quit");
       printf("\nEnter Your Choice: ");
       scanf("%d",&op);
       switch(op)
    { case 1: p1=create();break;
      case 2: p2=create();break;
      case 3: print(p1);break;
      case 4: print(p2);break;
      case 5: p3=padd(p1,p2);
          print(p3);break;
      case 6: p3=pmul(p1,p2);
          print(p3);break;
      case 7: printf("\nEnter the value of X:");
          scanf("%f",&x);
          value=eval(p1,x);
          printf("\nEvaluated value = %6.2f",value);
          break;
      }
       }while(op!=8);
 }

 /*
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ OUTPUT ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


1)Create first polynomial
2)Create second polynomial
3)Print first polynomial
4)Print second polynomial
5)Add
6)Multiply
7)Evaluate First Polynomial
8)Quit

Enter Your Choice: 1

Enter No. of Terms:2

enter a term as a tuple of (power,coefficient) : 1 3 2 1

Enter Your Choice: 3

  3.00x^1     1.00x^2


Enter Your Choice: 2

Enter No. of Terms:2

enter a term as a tuple of (power,coefficient) : 5 1 6 2


Enter Your Choice: 5

  3.00x^1     1.00x^2     1.00x^5     2.00x^6
1)Create first polynomial


Enter Your Choice: 6

  3.00x^6     7.00x^7     2.00x^8

Enter Your Choice: 7

Enter the value of X:2

Evaluated value =  10.00
 */

"C program for merging of two Singly linked list"

/*Merging of linked lists with sorted data
   */

#include <stdio.h>
#include <conio.h>
#include <stdlib.h>

typedef struct node
 { int data;
   struct node *next;
 }node;
node *merge(node *l1,node *l2);
node *create_normal();
node *create_sorted();
void print(node *head);
void sort(node *head);
void main()
 { node *head1,*head2,*head3;
   clrscr();
   printf("\nCreating Normal(unsortrd) linked list \n");
   head1=create_normal();
   printf("\nCreating sorted linked list \n");
   head2=create_sorted();
   printf("\nFirst LInked list(Before Sorting):");
   print(head1);
   sort(head1);
   printf("\nFirst Linked list(After Sorting):");
   print(head1);
   printf("\nSecond Linked list:");
   print(head2);
   head3=merge(head1,head2);
   printf("\nFinal List:");
   print(head3);
   getch();
 }
node *merge(node *l1,node *l2)
   { node *l,*p;
     l=NULL;
     while(l1!=NULL && l2!=NULL)
       { if(l1->data < l2->data)
       { if(l==NULL)
          { l=p=l1;
        l1=l1->next;
          }
         else
          { p->next=l1;
        l1=l1->next;
        p=p->next;
          }
       }
     else
       { if(l==NULL)
          { l=p=l2;
        l2=l2->next;
          }
         else
          { p->next=l2;
        l2=l2->next;
        p=p->next;
          }
       }
      }
      if(l1!=NULL)
       { if(l==NULL)
       l=l1;
     else
       p->next=l1;
       }
      if(l2!=NULL)
       { if(l==NULL)
       l=l2;
     else
       p->next=l2;
       }
    return(l);
  }
 node *create_normal()
  { node *head=NULL,*p;
    int n,x,i;
    printf("\nNumber of nodes:");
    scanf("%d",&n);
    printf("\nEnter data:");
    for(i=1;i<=n;i++)
     { scanf("%d",&x);
       if(head==NULL)
     { p=head=(node*)malloc(sizeof(node));
       p->next=NULL;
     }
       else
    {p->next=(node*)malloc(sizeof(node));
    p=p->next;
    p->next=NULL;
    }
       p->data=x;
    }
   return(head);
 }
node *create_sorted()
  { node *head=NULL,*p,*q;
    int n,x,i;
    printf("\nNumber of nodes:");
    scanf("%d",&n);
    printf("\nEnter data:");
    for(i=1;i<=n;i++)
     { scanf("%d",&x);
       p=(node*)malloc(sizeof(node));
       p->data=x;
       p->next=NULL;
       if(head==NULL || x<head->data)
      { p->next=head;
        head=p;
      }
       else
    { q=head;
      while(q->next !=NULL && x>q->next->data)
        q=q->next;
      p->next=q->next;
      q->next=p;
    }
     }
   return(head);
 }
 void print(node *head)
  { printf("\n");
   while(head != NULL)
    { printf("%5d",head->data);
      head=head->next;
    }
  }
void sort(node *head)
  { int i,j,n,temp;
    node *p;
   /*counting number of nodes*/
    for(n=0,p=head;p!=NULL;p=p->next)
       n++;
    for(i=1;i<n;i++)
     {p=head;
      for(j=0;j<n-i;j++)
       {if(p->data > p->next->data)
      { temp=p->data;
        p->data=p->next->data;
        p->next->data=temp;
      }
    p=p->next;
       }
      }
    }
    /*
    OUTPUT:-

Creating Normal(unsortrd) linked list

Number of nodes:2

Enter data:42 12

Creating sorted linked list

Number of nodes:3

Enter data:12 68 41

First LInked list(Before Sorting):
   42   12
First Linked list(After Sorting):
   12   42
Second Linked list:
   12   41   68
Final List:
   12   12   41   42   68

    */



                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               
                                                                               

"C program on singly linked list"

/*Operations on SLL(singly linked list)*/


#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
typedef struct node
   { int data;
     struct node *next;
   }node;

node *create();
node *insert_b(node *head,int x);
node *insert_e(node *head,int x);
node *insert_in(node *head,int x);
node *delete_b(node *head);
node *delete_e(node *head);
node *delete_in(node *head);
node *reverse(node *head);
void search(node *head);
void print(node *head);

void main()
{ int op,op1,x;
  node *head=NULL;
  clrscr();
  do
    {
      printf("\n\n1)create\n2)Insert\n3)Delete\n4)Search");
      printf("\n5)Reverse\n6)Print\n7)Quit");
      printf("\nEnter your Choice:");
      scanf("%d",&op);
      switch(op)
       { case 1:head=create();break;
     case 2:printf("\n\t1)Beginning\n\t2)End\n\t3)In between");
        printf("\nEnter your choice : ");
        scanf("%d",&op1);
        printf("\nEnter the data to be inserted : ");
        scanf("%d",&x);
        switch(op1)
         {  case 1: head=insert_b(head,x);
                break;
            case 2: head=insert_e(head,x);
                break;
            case 3: head=insert_in(head, x);
                break;
          }
        break;
     case 3:printf("\n\t1)Beginning\n\t2)End\n\t3)In between");
        printf("\nEnter your choice : ");
        scanf("%d",&op1);
        switch(op1)
         {  case 1:head=delete_b(head);
               break;
            case 2:head=delete_e(head);
               break;
            case 3:head=delete_in(head);
               break;
          }
         break;
     case 4:search(head);break;
     case 5:head=reverse(head);
        print(head);
        break;
     case 6:print(head);break;
       }
    }while(op!=7);
}

node *create()
{ node *head,*p;
  int i,n;
  head=NULL;
  printf("\n Enter no of data:");
  scanf("%d",&n);
  printf("\nEnter the data:");
  for(i=0;i<n;i++)
   {
     if(head==NULL)
     p=head=(node*)malloc(sizeof(node));
     else
       {
     p->next=(node*)malloc(sizeof(node));
     p=p->next;
       }
       p->next=NULL;
       scanf("%d",&(p->data));
   }
 return(head);
}

node *insert_b(node *head,int x)
{   node *p;
    p=(node*)malloc(sizeof(node));
    p->data=x;
    p->next=head;
    head=p;
    return(head);
}

node *insert_e(node *head,int x)
{   node *p,*q;
    p=(node*)malloc(sizeof(node));
    p->data=x;
    p->next=NULL;
    if(head==NULL)
       return(p);
    //locate the last node
    for(q=head;q->next!=NULL;q=q->next);
    q->next=p;
    return(head);
}

node *insert_in(node *head,int x)
{   node *p,*q;
    int y;
    p=(node*)malloc(sizeof(node));
    p->data=x;
    p->next=NULL;
    printf("\Insert after which number ? : ");
    scanf("%d",&y);
    //locate the lthe data 'y'
    for(q=head ; q != NULL && q->data != y ; q=q->next)
    ;
    if(q!=NULL)
      {
    p->next=q->next;
    q->next=p;
      }
    else
       printf("\nData not found ");
    return(head);
}
node *delete_b(node *head)
{
  node *p,*q;
  if(head==NULL)
     {
    printf("\nUnderflow....Empty Linked List");
    return(head);
     }
  p=head;
  head=head->next;
  free(p);
  return(head);

}
node *delete_e(node *head)
{
  node *p,*q;
  if(head==NULL)
     {
    printf("\nUnderflow....Empty Linked List");
    return(head);
     }
  p=head;
  if(head->next==NULL)
     { // Delete the only element
       head=NULL;
       free(p);
       return(head);
     }
//Locate the last but one node
   for(q=head;q->next->next !=NULL;q=q->next)
   ;
   p=q->next;
   q->next=NULL;
   free(p);
   return(head);
}
node *delete_in(node *head)
{
  node *p,*q;
  int x,i;
  if(head==NULL)
     {
    printf("\nUnderflow....Empty Linked List");
    return(head);
     }
  printf("\nEnter the data to be deleted : ");
  scanf("%d",&x);
  if(head->data==x)
     { // Delete the first element
       p=head;
       head=head->next;
       free(p);
       return(head);
     }
//Locate the node previous to one to be deleted
   for(q=head;q->next->data!=x && q->next !=NULL;q=q->next )
   ;
   if(q->next==NULL)
     {
       printf("\nUnderflow.....data not found");
       return(head);
     }
   p=q->next;
   q->next=q->next->next;
   free(p);
   return(head);
}

void search(node *head)
{ node *p;
  int data,loc=1;
  printf("\nEnter the data to be searched: ");
  scanf("%d",&data);
  p=head;
  while(p!=NULL && p->data != data)
   { loc++;
     p=p->next;
   }

  if(p==NULL)
   printf("\nNot found:");
  else
   printf("\nFound at location=%d",loc);
}
void print(node *head)
{ node *p;
 printf("\n\n");
 for(p=head;p!=NULL;p=p->next)
  printf("%d  ",p->data);
}

node *reverse(node *head)
  { node *p,*q,*r;
    p=NULL;
    q=head;
    r=q->next;
    while(q!=NULL)
      {
    q->next=p;
    p=q;
    q=r;
    if(q!=NULL)
       r=q->next;
      }
   return(p);
  }
  /*
  OUTPUT:-
1)create
2)Insert
3)Delete
4)Search
5)Reverse
6)Print
7)Quit
Enter your Choice:1

Enter no of data:2

Enter the data:23 34

Enter your Choice:2

    1)Beginning
    2)End
    3)In between
Enter your choice : 2

Enter the data to be inserted : 25

Enter your Choice:3

    1)Beginning
    2)End
    3)In between
Enter your choice : 3

Enter the data to be deleted : 34

1)create
2)Insert
3)Delete
4)Search
5)Reverse
6)Print
7)Quit
Enter your Choice:7

Enter your Choice:4

Enter the data to be searched: 34

Not found:

Enter your Choice:5

25  23

Enter your Choice:6

25  23
*/

Few Linux App & commands which is going to used to Build AOSP(Android Open Source Project) Source Code

1. sudo apt-get install git-core gnupg flex bison gperf build-essential zip curl zlib1g-dev gcc-multilib g++-multilib libc6-dev-i386 lib32n...