Google

Wednesday, 18 June 2014

MCA Programs




CONCEPT OF CIRCULAR LINKED LIST USING ARRAY

# include <stdio.h>

# include <conio.h>

int a[20],i,n=0,ch;

intpos,newnode;

void menu()

{

printf("CIRCULAR LINKED LIST - MENU \n");

printf("-------------------------\n");

printf("1. Create New list \n");

printf("2. Display \n");

printf("3. Insert \n");

printf("4. Delete \n");

printf("5. Update \n");

printf("6. Exit \n");

printf("Enter your choice \n");

scanf("%d",&ch);

}

void create()

{   

if(n==0)

   {

printf("How many Nodes?");

scanf("%d",&n);

for(i=1;i<=n;i++)

     {

printf("\t Enter Node=>%d: ",i);

scanf("%d",&a[i]);

     }

printf("\n The circular linkedlist is created\n");

}0

else

printf("\n The list is Already created. Try with other options\n");

}

void display()

{

if(n==0)

printf("\n The circular Linked list is empty\n");

else

     {

printf("\t\t<<CURRENT LIST >>\n");

for(i=1;i<=n;i++)

         {

printf("%d-> ",a[i]);

         }

printf("%d\n",a[1]);

     }

}

void insert()

{

display();

if(n!=0)

    {

printf("Enter the position : ");

scanf("%d",&pos);

if (pos>0 && pos<=(n+1))

   {

printf("Enter the NEW NODE: ");

scanf("%d",&newnode);

for(i=n;i>=pos;i--)

 {

a[i+1]=a[i];

           }

a[pos]=newnode;

            ++n;

printf("\n The given node has been successfully inserted..\n");

display();

        }

else

printf("\n The Given Position is out of range\n");

   }

}

void dele()

{

display();

if(n!=0)

      {

printf("Enter the position : ");

scanf("%d",&pos);

if(pos>0 && pos<=n)

          {

for(i=pos;i<n;i++)

              {

a[i]=a[i+1];

               }

            --n;

printf("\n The given node has been successfully deleted..\n");

display();

       }

else

printf("\n The Given Position is out of range\n");

   }

}

void update()

{

display();

if(n!=0)

     {

printf("Enter the position : ");

scanf("%d",&pos);

if(pos>0 && pos<=n)

          {

printf("Enter the NEW NODE: ");

scanf("%d",&newnode);

a[pos]=newnode;

printf("\n The given node has been successfully modified..\n");

display();

          }

else

printf("\n The Given Position is out of range\n");

            }}

void main()

{

while(1)//Infinite loop

     {

clrscr();

menu()

switch(ch)

       {

case 1:         create();         break;

case 2:         display();         break;

case 3:         insert();         break;

case 4:         dele();         break;

case 5:

update();

break;

case 6:

exit(0);

default:

printf("\n Invalid Option, Try Again!\n");

       }

getch();

   }               //end of while(1)

}

OUTPUT:

CIRCULAR LINKED LIST - MENU

-------------------------

1. Create New list

2. Display

3. Insert

4. Delete

5. Update

6. Exit

Enter your choice

1

How many Nodes?5

         Enter Node=>1: 1001

         Enter Node=>2: 2002

         Enter Node=>3: 3003

         Enter Node=>4: 4004

         Enter Node=>5: 5005

The circular linkedlist is created

CIRCULAR LINKED LIST - MENU

-------------------------

1. Create New list

2. Display

3. Insert

4. Delete

5. Update

6. Exit

Enter your choice

2

<<CURRENT LIST >>

1001-> 2002-> 3003-> 4004-> 5005-> 1001

CIRCULAR LINKED LIST - MENU

-------------------------

1. Create New list

2. Display

3. Insert

4. Delete

5. Update

6. Exit

Enter your choice

3

<<CURRENT LIST >>

1001-> 2002-> 3003-> 4004-> 5005-> 1001

Enter the position : 3

Enter the NEW NODE: 333

The given node has been successfully inserted..

<<CURRENT LIST >>

1001-> 2002-> 333-> 3003-> 4004-> 5005-> 1001

CIRCULAR LINKED LIST - MENU

-------------------------

1. Create New list

2. Display

3. Insert

4. Delete

5. Update

6. Exit

Enter your choice

4

<<CURRENT LIST >>

1001-> 2002-> 333-> 3003-> 4004-> 5005-> 1001

Enter the position : 4

The given node has been successfully deleted..

<<CURRENT LIST >>

1001-> 2002-> 333-> 4004-> 5005-> 1001

CIRCULAR LINKED LIST - MENU

-------------------------

1. Create New list

2. Display

3. Insert

4. Delete

5. Update

6. Exit

Enter your choice

5

<<CURRENT LIST >>

1001-> 2002-> 333-> 4004-> 5005-> 1001

Enter the position : 3

Enter the NEW NODE: 3000

 The given node has been successfully modified..

<<CURRENT LIST >>

1001-> 2002-> 3000-> 4004-> 5005-> 1001

STACK OPERATIONS

#include <stdio.h>

#include <conio.h>

#define MAX 5

struct node

{          int data;

            struct node*next;

}*tos;

int count=0,ch;

void menu()

{

            printf("STACK OPERATIONS - MENU\n");

            printf("---------------------------\n");

            printf("1.PUSH (Add new)\n");

            printf("2.POP (Delete)\n");

            printf("3.LIST\n");

            printf("4.Exit\n");

            printf("Enter your choice: ");

            scanf("%d",&ch);

}

void list()

{

            struct node*tmp;

                        if (tos==NULL)

                        printf("The stack is empty....\n");

                        else

                        {

                        tmp=tos;

                        printf("\n << CURRENT STACK STATUS >>\n\n");

                        printf("\t TOP-> ");

                                    while (tmp!=NULL)

                                    {          printf("%d \n\t\t",tmp->data);

                                                tmp=tmp->next;

                                    }

                        }

}

void push()

{          struct node*tmp;

                        if (count==MAX)

                        printf("The stack is FULL....\n");

                        else

                        {

                        tmp=(struct node*)malloc(sizeof(struct node));

                        list();

                        printf("\n \t Enter the NEW NODE: ");

                        scanf("%d",&tmp-> data);

                        tmp->next=tos;

                        tos=tmp;

                        ++count;

                        printf("\n\t NEW ITEM PLACED IN THE STACK...\n");

                        list();

                        }

}

void pop()

{                      if (tos==NULL)

                        printf("The stack is EMPTY....\n");

                        else

                      

{          list();

                                    printf("\n \t The popped Item is: %d ",tos->data);

                                    tos=tos->next;

                                    --count;

                                    list();

                        }

}

void main()

{          while(1)

            {          clrscr();

                        menu();

                        switch(ch)

                        {          case 1:             push();             break;

                                    case 2:             pop();               break;

                                    case 3:             list();                break;

                                    case 4:             exit(0);

                                    default:

                                    printf("\n Invalid Option... Try Again!!!...\n");

                          }

            getch();

            }

}

OUTPUT:

STACK OPERATIONS - MENU

---------------------------

1.PUSH (Add new)

2.POP (Delete)

3.LIST

4.Exit

Enter your choice: 1

The stack is empty....

         Enter the NEW NODE: 10

         NEW ITEM PLACED IN THE STACK...

<< CURRENT STACK STATUS >>

         TOP-> 10

STACK OPERATIONS - MENU

---------------------------

1.PUSH (Add new)

2.POP (Delete)

3.LIST

4.Exit

Enter your choice: 1

<< CURRENT STACK STATUS >>

         TOP-> 10

         Enter the NEW NODE: 200

         NEW ITEM PLACED IN THE STACK...

<< CURRENT STACK STATUS >>

         TOP-> 200

                10

STACK OPERATIONS - MENU

---------------------------

1.PUSH (Add new)

2.POP (Delete)

3.LIST

4.Exit

Enter your choice: 1

<< CURRENT STACK STATUS >>

         TOP-> 200

                10

         Enter the NEW NODE: 300

         NEW ITEM PLACED IN THE STACK...

<< CURRENT STACK STATUS >>

         TOP-> 300

                200

                10

STACK OPERATIONS - MENU

---------------------------

1.PUSH (Add new)

2.POP (Delete)

3.LIST

4.Exit

Enter your choice: 2

<< CURRENT STACK STATUS >>

         TOP-> 300

                200

                10

         The popped Item is: 300

<< CURRENT STACK STATUS >>

         TOP-> 200

                10

QUEUE OPERATIONS USING LINKED LIST

#include <stdio.h>

#include <conio.h>

#define MAX 5

struct node

{          int data;

            struct node*next;

}*first,*last;

int count=0,ch;

void menu()

{          printf("QUEUE OPERATIONS - MENU\n");

            printf("---------------------------\n");

            printf("1.Add new\n");

            printf("2.Delete\n");

            printf("3.LIST\n");

            printf("4.Exit\n");

            printf("Enter your choice: ");

            scanf("%d",&ch);

}

void list()

{          struct node*tmp;

                        if (first==NULL)

                        printf("The Queue is empty....\n");

                        else

                        {

                        tmp=first;

                        printf("\n << CURRENT QUEUE STATUS >>\n\n");

                        printf("\t fIRST<- ");

                                    while (tmp!=NULL)

                                    {          printf("%d<- ",tmp->data);

                                                tmp=tmp->next;

                                    }

                                    printf("Last \n");

                        }

}

voidaddnew()

{          struct node*tmp;

                        if (count==MAX)

                        printf("The Queue is FULL....\n");

                        else

                        {

                        tmp=(struct node*)malloc(sizeof(struct node));

                        list();

                        printf("\n \t Enter the NEW NODE: ");

                        scanf("%d",&tmp-> data);

                        tmp->next=NULL;

                                    if(first==NULL)

                                    first=tmp;

                                    else

                                    last->next=tmp;

                                    last=tmp;

                                    ++count;

                                    printf("\n\t NEW ITEM PLACED IN THE QUEUE...\n");

                                    list();

                      

}}

void dele()

{                      if (first==NULL)

                        printf("The Queue is EMPTY....\n");

                        else

                        {          list();

                                    printf("\n \t The Served Item is: %d ",first->data);

                                    first=first->next;

                                    --count;

                                    list();

                        }          }

void main()

{

            while(1)

            {          clrscr();

                        menu();

                        switch(ch)

                        {          case 1:             addnew();                    break;

                                    case 2:             dele();                          break;

                                    case 3:             list();                            break;

                                    case 4:             exit(0);

                                    default:

                                    printf("\n Invalid Option... Try Again!!!...\n");

                          }        getch();

            }

}

OUTPUT:

QUEUE OPERATIONS - MENU

---------------------------

1.Add new

2.Delete

3.LIST

4.Exit

Enter your choice: 1

The Queue is empty....

         Enter the NEW NODE: 1001

         NEW ITEM PLACED IN THE QUEUE...

<< CURRENT QUEUE STATUS >>

fIRST<- 1001<- Last

QUEUE OPERATIONS - MENU

---------------------------

1.Add new

2.Delete

3.LIST

4.Exit

Enter your choice: 1

<< CURRENT QUEUE STATUS >>

fIRST<- 1001<- Last

         Enter the NEW NODE: 2002

         NEW ITEM PLACED IN THE QUEUE...

<< CURRENT QUEUE STATUS >>

fIRST<- 1001<- 2002<- Last

QUEUE OPERATIONS - MENU

---------------------------

1.Add new

2.Delete

3.LIST

4.Exit

Enter your choice: 3

<< CURRENT QUEUE STATUS >>

fIRST<- 1001<- 2002<- Last

QUEUE OPERATIONS - MENU

---------------------------

1.Add new

2.Delete

3.LIST

4.Exit

Enter your choice: 2

<< CURRENT QUEUE STATUS >>

fIRST<- 1001<- 2002<- Last

         The Severed Item is: 1001

<< CURRENT QUEUE STATUS >>

fIRST<- 2002<- Last

BINARY SEARCH USING RECURSIVE FUNCTIONS

# include <stdio.h>

# include <conio.h>

int a[20],key;

intbinarysearch(intlbound, intubound)

{

            int mid=(lbound+ubound)/2;

            if(lbound>ubound) return 0; //Not found

            if(key==a[mid]) return mid; //Found

            if(key>a[mid]) lbound=mid+1;

            if(key<a[mid]) ubound=mid-1;

            return(binarysearch(lbound, ubound));

}

void main()

{

            intn,i,j,retval,tmp,ta[20];

            clrscr();

            printf("How many numbers ?  ");        scanf("%d",&n);

            printf("Enter the Array Elements one by one \n");

                        for(i=1;i<=n;i++)

                        {

printf("\ta[%d]=> ",i);

                                    scanf("%d",&a[i]);

                                    ta[i]=a[i];

                        }

            printf("Enter the key value: ");

            scanf("%d",&key);

            printf("Sorted Order\n");

                        for(i=1;i<=n;i++)

                        {

                                    for(j=i;j<=n;j++)

                                                if(a[i]>a[j])

                                                {

                                                            tmp=a[i];

                                                            a[i]=a[j];

                                                            a[j]=tmp;

                                                }

                                                printf("%d\t",a[i]);

                        }

                        retval=binarysearch(1,n);

                        printf("\n The given key '%d' is ",key);

                                    if(retval==0)

                                    printf("Not Found");

                                    else

                                    {

printf("Found at the following position(s) \n");

printf("\tNos.     Position\n");

for(i=1;i<=n;i++)

                               {

printf("\t%5d",ta[i]);

if(ta[i]==key)

                                     {

textcolor(GREEN+BLINK);

cprintf("<- ");

printf("%d",i);

                                      }

printf("\n");

                        }

          }

                                    getch();

}

OUTPUT:

How many numbers ?  6

Enter the Array Elements one by one

a[1]=> 23

a[2]=> 12

a[3]=> 10

a[4]=> 55

a[5]=> 12

a[6]=> 34

Enter the key value: 12

Sorted Order

10      12      12      23      34      55

 The given key '12' is Found at the following position(s)

        Nos.     Position

           23

           12<- 2

           10

           55

           12<- 5

           34

FIBONACCI SERIES SEARCH

# include<stdio.h>

#include <conio.h>

void main()

{

            intn,i,a=-1,b=1,c,key,flag=0;

            clrscr();

            printf("How many Terms? ");

            scanf("%d",&n);

            printf("Enter the key value: ");

            scanf("%d",&key);

            printf("The Fibonacci Series with %d Terms \n",n);

            for(i=1;i<=n;i++)

            {

                        c=a+b;

                                    if(c==key)

                                    {

                                                textcolor(CYAN+BLINK);

                                                cprintf("%d",c);

                                                flag=1;  //Found

                                    }

                                    else

                                    printf("%d",c);

                                    printf(",");

                                    a=b;

                                    b=c;

            }

            printf(".......\n");

            printf("The Key Value '%d' is   ",key);

                        if(flag==0)

                        printf("Not Found....\n");

                        else

                        printf("Blinking above......\n");

                        getch();

}

OUTPUT:

How many Terms? 20

Enter the key value: 55

The Fibonacci Series with 20 Terms

0,1,1,2,3,5,8,13,21,34,55,89,144,233,377,610,987,1597,2584,4181,.......

The Key Value '55' is   Blinking above......

CONVERT INFIX EXPR TO POSTFIX EXPR

# include <stdio.h>

# include <conio.h>

void main()

{

            char infix[60],postfix[60],stack[20];

            inti,j=0,k=0;

            clrscr();

            printf("Enter the Infix Expression : ");

            gets(infix);

                        for(i=0;infix[i]!='\0';i++)

                        switch(infix[i])

                        {

                                        //      j    postfix k   stack

case '+':      //(a+b)  0    a       1     (

case '-':       //      1    b       2     +

case '*':       //      2    +

case '/':       //      3    \0

                                    case '~':

                                    case '(': stack[++k]=infix[i];break;

                                    case ')': while(stack[k]!='(' && k>0)

                                                            {          postfix[j++]=stack[k--];

                                                            }

                                                            k--;

                                    break;

                                    default:

                                    postfix[j++]=infix[i];

                        }

                        while(k>0)

                        postfix[j++]=stack[k--];

                        postfix[j]='\0';

printf("The corresponding postfix Expression:%s\n",postfix);

                        getch();

}

OUTPUT:

Sample - 1

Enter the Infix Expression : (a+b)*c

The corresponding postfix Expression :ab+c*

sample - 2

Enter the Infix Expression :a+b

The corresponding postfix Expression :ab+

BINARY TREE TRAVERSAL (PRE-ORDER, IN-ORDER AND POST ORDER)

# include <stdio.h>

# include <conio.h>

Struct bintree

{

            Struct bintree*lchild;

            char data;

            struct bintree*rchild;

};

void create(struct bintree*bt)

{

            flushall();

            scanf("%c",&bt->data);

            if(bt->data!='0')

            {

                        bt->lchild=(struct bintree *)malloc(sizeof(struct bintree));

                        printf("\tLeft Child of %c=> ",bt->data);

                        create(bt->lchild);

                        bt->rchild=(structbintree *)malloc(sizeof(structbintree));

                        printf("\tRight Child of %c=> ",bt->data);

                        create(bt->rchild);

            }

}

void preorder(structbintree*bt)

{

            if (bt->data!='0')

            {

                        printf("%c",bt->data);

                        preorder(bt->lchild);

                        preorder(bt->rchild);

            }

}

voidinorder(structbintree*bt)

{

            if (bt->data!='0')

            {

                        inorder(bt->lchild);

                        printf("%c",bt->data);

                        inorder(bt->rchild);

            }

}

voidpostorder(structbintree*bt)

{

            if (bt->data!='0')

            {

                        postorder(bt->lchild);

                        postorder(bt->rchild);

                        printf("%c",bt->data);              }          }

void main()

{

            structbintree*root;

            clrscr();

            root=(structbintree*)malloc(sizeof(structbintree));

            root->lchild=root->rchild=NULL;

            printf("To use any Arithmetic Expression\n");

            printf("\t<< Enter 0 to terminate >>\n");

            printf("Enter the Root Node :  ");

            create(root);

            printf("BINARY TREE TRAVERSAL\n");

            printf("_______________________\n");

            printf("PreOrder : ");

            preorder(root);

            printf("\nInOrder : ");

            inorder(root);

            printf("\nPostOrder : ");

            postorder(root);

            getch();            }

OUTPUT:

To use any Arithmetic Expression

<< Enter 0 to terminate >>

Enter the Root Node :  *

        Left Child of *=> +

        Left Child of +=> A

        Left Child of A=> 0

        Right Child of A=> 0

        Right Child of +=> B

        Left Child of B=> 0

        Right Child of B=> 0

        Right Child of *=> C

        Left Child of C=> 0

        Right Child of C=> 0

BINARY TREE TRAVERSAL

PreOrder : *+ABC

InOrder : A+B*C

PostOrder : AB+C*

QUICK SORT ALGORITHM

# include <stdio.h>

# include <conio.h>

int a[20];

void quicksort(int low, int high)

{

            int key=a[low],i=low,j=high+1,tmp,ii;

                        if (low<high)

                        {do

                        {       do i++; while(a[i]<=key);

                                                do j--; while(a[j]>key);

                                                            if(i<=j)

                                        {      tmp=a[i];          a[i]=a[j];           a[j]=tmp;          }

                                    }while(i<=j);                tmp=a[low];     a[low]=a[j];      a[j]=tmp;

                                    quicksort(low,j-1);       quicksort(j+1,high);     }}

void main()

{

            intn,i;

            clrscr();

            printf("How many Numbers ? ");

            scanf("%d",&n);

            printf("Enter the Array Elements\n");

                        for(i=1;i<=n;i++)

                        {          printf("\t A[%d] => ",i);

                                    scanf("%d", &a[i]);                  }

            quicksort(1,n);

            printf("The sorted Numbers in Ascending Order\n");

            for(i=1;i<=n;i++)    

                        printf("\t %d \n",a[i]);

                        getch();            }

OUTPUT:

How many Numbers ? 6

Enter the Array Elements

A[1] => -1001

A[2] => -2002

A[3] => 2002

A[4] => 1001

A[5] => 3003

A[6] => -3003

The sorted Numbers in Ascending Order

         -3003

         -2002

         -1001

         1001

         2002

         3003

HEAP SORT ALGORITH

# include <stdio.h>

# include <conio.h>

void main()

{

            int a[20],i,n,m,tmp;

            clrscr();

            printf("Enter the no of Elements: ");

            scanf("%d",&n);

            printf("\n Enter the Array Elements\n");

            for (i=1;i<=n;i++)

            {          printf("\tA[%d]=> ",i);

                        scanf("%d",&a[i]);       }

            m=n;

            while (n>0)      // Heap Sort Technique

            {          for(i=n;i>1;i--)

                        if(a[i/2]>a[i])

                        {          tmp=a[i/2];       a[i/2]=a[i];        a[i]=tmp;          }

                                    tmp=a[i];          a[i]=a[n];          a[n]=tmp;         n--;

            }

            printf("The Sorted Numbers in Ascending Order \n ");

            for(i=m;i>=1;i--)

            printf("\t%d\n ",a[i]);

            getch();

}

OUTPUT:

Enter the no of Elements: 5

 Enter the Array Elements

A[1]=> 23

A[2]=> 12

A[3]=> 45

A[4]=> 34

A[5]=> 67

The Sorted Numbers in Ascending Order

        12

        23

        34

        45

        67

DOUBLY LINKED LIST

# include <stdio.h>

# include <conio.h>

structdlink

{

            structdlink*prev;

            int data;

            structdlink*next;

}*first,*cnode,*temp;

intch,ncount=0,pos,i;

void menu()

{          printf("DOUBLY LINKED LIST - MENU \n");

            printf("------------------------------\n");

            printf("1. Create a New list\n");

            printf("2. Insert \n");

            printf("3. Delete\n");

            printf("4. Update\n");

            printf("5. Display\n");

            printf("6. Exit\n");

            printf("Enter Your Choice : ");

            scanf("%d",&ch);

}

void display()

{

            if (ncount!=0)

                        {          structdlink*temp=first;

                                    printf("\n\t\t<< CURRENT STATUS >>\n");

                                    printf("The forward List : ");

                                                while(temp->data!=0)

                                                {          printf("->%d",temp->data);

                                                            temp=temp->next;        }

                                    temp=temp->prev;

                                    printf("\nThe Backward List: ");

                                                while(temp!=NULL)

                                                {          printf("-> %d",temp->data);

                                                            temp=temp->prev;

                                                }                      }

                        else

                        printf("\nDoubly Linked List is Empty........\n");

}

void create()

{          if (first==NULL)

                        {          cnode=(structdlink*)malloc(sizeof(structdlink));

                                    first=cnode;

                                    printf("\n\t\t<< Enter 0 to Terminate >>\n");

                                    printf("Enterthe New Node : ");

                                    scanf("%d",&cnode->data);

cnode->prev=NULL;

while(cnode->data!=0)

          

{             temp=(structdlink*)malloc(sizeof(structdlink));

                                                            printf("Enterthe New Node : ");

                                                            scanf("%d",&temp->data);

                                                            cnode->next=temp;

                                                            temp->prev=cnode;

                                                            cnode=temp;

                                                            ++ncount;

                                                }

                                    cnode->next=NULL;

                                    printf("\nThe Doubly Linked List is created.. ");

                        }

                        else

printf("\nDoubly Linked List is Already created.Try Again........\n");

}

void insert()

{          display();

            if (first!=NULL)

                        {

printf("\nEnter the Position : ");

scanf("%d",&pos);

if(pos>0 && pos<=(ncount+1))

                    {        temp=(structdlink*)malloc(sizeof(structdlink));

printf("Enterthe New Node : ");

scanf("%d",&temp->data);

if(pos==1)

                       {   temp->next=first;

first->prev=temp;

temp->prev=NULL;

first=temp;

                       }

else

                       {    cnode=first;

for(i=1;i<pos-1;i++)

cnode=cnode->next;

temp->next=cnode->next;

cnode->next->prev=temp;

cnode->next=temp;

temp->prev=cnode;

                        }

                       ++ncount;

printf("\n The Given Node is Inserted...\n");

                                                            display();

                 }

else

printf("\nThe Given Position is out of range..\n");

            }

}

void dele()

{

            display();

            if (first!=NULL)

        

{

printf("\nEnter the Position : ");

scanf("%d",&pos);

if(pos>0 &&pos<=ncount)

               {

cnode=first;

if(pos==1)

                      {

first=first->next;

first->prev=NULL;

                       }

else

                       {

for(i=1;i<pos-1;i++)

cnode=cnode->next;

cnode->next=cnode->next->next;

cnode->next->prev=cnode;

                        }

                      --ncount;

printf("\n The Given Node is Deleted...\n");

display();

               }

else

printf("\nThe Given Position is out of range..\n");

            }

}

void update()

{

            intnewnode;

            display();

            if (first!=NULL)

          {

printf("\nEnter the Position : ");

scanf("%d",&pos);

if(pos>0 &&pos<=ncount)

             {

cnode=first;

printf("Enterthe New Node : ");

scanf("%d",&newnode);

for(i=1;i<pos;i++)

cnode=cnode->next;

cnode->data=newnode;

printf("\n The Given Node is Updated...\n");

display();

               }

else

printf("\nThe Given Position is out of range..\n");

            }

}

void main()

{

            while(1)

          

{

                        clrscr();

                        menu();

                        switch(ch)

                        {          case 1:             create();           break;

                                    case 2:             insert();            break;

                                    case 3:             dele();              break;

                                    case 4:             update();          break;

                                    case 5:             display();         break;

                                    case 6:             exit(0);

                                    default:

                                    printf("\n Invalid Option... Try Again!!!...\n");

                          }

            getch();

            }

}

OUTPUT:

DOUBLY LINKED LIST - MENU

1. Create a New list

2. Insert

3. Delete

4. Update

5. Display

6. Exit

Enter Your Choice : 1

<< Enter 0 to Terminate >>

Enter the New Node : 1011

Enter the New Node : 2011

Enter the New Node : 3011

Enter the New Node : 4011

Enter the New Node : 5011

Enter the New Node : 0

The Doubly Linked List is created..

DOUBLY LINKED LIST - MENU

1. Create a New list

2. Insert

3. Delete

4. Update

5. Display

6. Exit

Enter Your Choice :

5

<< CURRENT STATUS >>

The forward List : ->1011->2011->3011->4011->5011

The Backward List: -> 5011-> 4011-> 3011-> 2011-> 1011

DOUBLY LINKED LIST - MENU

1. Create a New list

2. Insert

3. Delete

4. Update

5. Display

6. Exit

Enter Your Choice : 2

<< CURRENT STATUS >>

The forward List : ->1011->2011->3011->4011->5011

The Backward List: -> 5011-> 4011-> 3011-> 2011-> 1011

Enter the Position : 6

Enter the New Node : 6011

The Given Node is Inserted...

<< CURRENT STATUS >>

The forward List : ->1011->2011->3011->4011->5011->6011

The Backward List: -> 6011-> 5011-> 4011-> 3011-> 2011-> 1011

DOUBLY LINKED LIST - MENU

------------------------------

1. Create a New list

2. Insert

3. Delete

4. Update

5. Display

6. Exit

Enter Your Choice : 3

<< CURRENT STATUS >>

The forward List : ->1011->2011->3011->4011->5011->6011

The Backward List: -> 6011-> 5011-> 4011-> 3011-> 2011-> 1011

Enter the Position : 6

The Given Node is Deleted...

<< CURRENT STATUS >>

The forward List : ->1011->2011->3011->4011->5011

The Backward List: -> 5011-> 4011-> 3011-> 2011-> 1011

DOUBLY LINKED LIST - MENU

------------------------------

1. Create a New list

2. Insert

3. Delete

4. Update

5. Display

6. Exit

Enter Your Choice : 4

<< CURRENT STATUS >>

The forward List : ->1011->2011->3011->4011->5011

The Backward List: -> 5011-> 4011-> 3011-> 2011-> 1011

Enter the Position : 2

Enterthe New Node : 3333

 The Given Node is Updated...

<< CURRENT STATUS >>

The forward List : ->1011->3333->3011->4011->5011

The Backward List: -> 5011-> 4011-> 3011-> 3333-> 1011

POLYNOMIAL ADDITION

#include <stdio.h>

#include <conio.h>

structaddpoly

{

intcoeff;

int power;

structaddpoly *next;

}*afirst,*alast,*bfirst,*blast,*cfirst,*clast,*tmp;

void create(int opt)

{          tmp=(structaddpoly *)malloc(sizeof(structaddpoly));

            printf("\tCoeff : ");

            scanf("%d",&tmp->coeff);

            printf("\tPower : ");

            scanf("%d",&tmp->power);

            tmp->next=NULL;

            if(opt==1)

            {          if(afirst==NULL)

                        afirst=tmp;

                        else

                        alast->next=tmp;

                        alast=tmp;

            }

            else

            {          if(bfirst==NULL)

                        bfirst=tmp;

                        else

                        blast->next=tmp;

                        blast=tmp;

            }

}

void result(intc,int p)

{          tmp=(structaddpoly *)malloc(sizeof(structaddpoly));

            tmp->coeff=c;

            tmp->power=p;

            tmp->next=NULL;

if(cfirst==NULL) cfirst=tmp;

                        else

                                    clast->next=tmp;

                                    clast=tmp;

}

void addition(structaddpoly *a,structaddpoly *b)

{          while(a!=NULL && b!=NULL)

            {          if(a->power > b->power)

                        {          result(a->coeff,a->power);

                                    a=a->next;

                        }

                        else if(a->power < b->power)

                        {          result(b->coeff,b->power);

                                    b=b->next;

                        }

                        else

                        {          result(a->coeff+b->coeff,a->power);

                                     a=a->next;   b=b->next;

                        }

            }

                      

while(a!=NULL)

                        {          result(a->coeff,a->power);

                                    a=a->next;

                        }

                        while(b!=NULL)

                        {          result(b->coeff,b->power);

                                    b=b->next;

                        }

}

void display(structaddpoly *c)

{          int p=0;

                        while(c!=NULL)

                        {          if(c->coeff>0 && p!=0)

                                    printf("+");

                                    printf("%d",c->coeff);

                                    if(c->power!=1 && c->power!=0)

                                    printf("X^%d",c->power);

                                    if(c->power==1)

                                    printf("X");

                                    p=1;  c=c->next;

                        }

                        printf("=0\n");

}

void main()

{          int n, i;

            clrscr();

            printf("Enter The No. of Terms for Polynomial A: ");

            scanf("%d",&n);

            printf("Enter the Polynomial A\n");

                        for(i=1;i<=n;i++)

                        {          printf("Term %d\n",i);

                                    create(1);

                        }

            printf("Enter the no of Terms for Polynomial B: ");

            scanf("%d",&n);

            printf("Enter the Polynomial B\n");

                        for(i=1;i<=n;i++)

                        {          printf("Term %d\n",i);

                                    create(2);

                        }

                        addition(afirst, bfirst);

                        printf("\n The Given Polynomials\n");

printf("\tA: ");  display(afirst);

printf("\tB: ");  display(bfirst);

                        printf("\n The Resultant Polynomial\n");

printf("\tC: ");  display(cfirst);

                        getch();

}

OUTPUT:

Enter The No. of Terms for Polynomial A: 3

Enter the Polynomial A

Term 1

Coeff : -2

Power : 3

Term 2

Coeff : 4

Power : 2

Term 3

Coeff : 5

Power : 1

Enter the no of Terms for Polynomial B: 3

Enter the Polynomial B

Term 1

Coeff : 7

Power : 3

Term 2

Coeff : 3

Power : 1

Term 3

Coeff : -6

Power : 0

 The Given Polynomials

        A: -2X^3+4X^2+5X=0

        B: 7X^3+3X-6=0

 The Resultant Polynomial

        C: 5X^3+4X^2+8X-6=0

TO FIND A SHORTEST PATH

# include <stdio.h>

# include <conio.h>

void main()

{          int a[20][20],visited[20][20]={0},path[20][4];

            int top=0,i,j,k,nrows,ncols,flag;

            clrscr();

            printf("How many Rows ? ");

            scanf("%d",&nrows);

            printf("How many Columns ? ");

            scanf("%d",&ncols);

            printf("Enter the Elements one by one\n");

            printf("<< Enter 0 for path and 1 for No path >>\n");

            for (i=1;i<=nrows;i++)

            for(j=1;j<=ncols;j++)

            {          again:

                        printf("\ta%d%d=> ",i,j);

                        scanf("%d",&a[i][j]);

                                    if(a[i][j]!=0 && a[i][j]!=1)

                                    {          printf("Invalid Input. Try again.......\n");

goto again;                             

}

            }

            printf("The Given TABLE (%dX%d)\n",nrows,ncols);

            for(i=1;i<=nrows;i++)

             {         for(j=1;j<=ncols;j++)

                        printf("%d\t",a[i][j]);

                        printf("\n");      }

                        if (a[1][1]==0 && a[nrows][ncols]==0)

                         {         path[++top][1]=1;

path[top][2]=1;          i=j=1;

visited[i][j]=1; //Already visited

while(1)

                                     {          flag=1;  //path Found

if(i==nrows+1 || j==ncols+1)        break;

if(i==nrows&& j==ncols)

                                                {          printf("The Path");

if(top<=0)

printf(" is Not Found\n");

for(k=1;k<=top;k++)

printf("->(%d,%d)",path[k][1],path[k][2]);

goto out;

                                                 }

if(a[i+1][j+1]==0 && (i+1)<=nrows&& (j+1)<=ncols&& visited[i+1][j+1]==0)

{           i++;           j++;       }

else if(a[i][j+1]==0 && (j+1)<=ncols&& visited[i][j+1]==0)   j++;

else if(a[i+1][j]==0 && (i+1)<=nrows&& visited[i+1][j]==0)   i++;

else if(a[i-1][j+1]==0 && (i-1)>0 && (j+1)<=ncols&& visited[i-1][j+1]==0)

      {   i--;           j++;

       }

else if(a[i+1][j-1]==0 && (i+1)<=nrows&& (j-1)>0 && visited[i+1][j-1]==0)

{  i++;           j--;

        }

else if(a[i][j-1]==0 && (j-1)>0 && visited[i][j-1]==0) j--;

else if(a[i-1][j]==0 && (i-1)>0 && visited[i-1][j]==0) i--;

else if(a[i-1][j-1]==0 && (i-1)>0 && (j-1)>0 && visited[i-1][j-1]==0)

       {

i-                    j--;

       }

else

       {     flag=0;    //Path Not found

         i=path[top][1];         j=path[top--][2];

        }

if(flag==1)

        {

path[++top][1]=i;         path[top][2]=j;         visited[i][j]=1;

        }      }    }

printf("\n There is No Path..\n");

out:    getch();

}

OUTPUT:

How many Rows ? 3

How many Columns ? 3

Enter the Elements one by one

<< Enter 0 for path and 1 for No path >>

        a11=> 0

        a12=> 0

        a13=> 0

        a21=> 1

        a22=> 1

        a23=> 0

        a31=> 1

        a32=> 1

        a33=> 0

The Given TABLE (3X3)

0       0       0

1       1       0

1       1       0

The Path->(1,1)->(1,2)->(2,3)->(3,3)