A mobile-responsive minimalist wp theme converted for Blogger

This is an example of a Blogger page, you could edit this to put information about yourself or your site so readers know where you are coming from. Find out more...

Program to count space, words, charactors,special charactors using Lex

****************************************Lex File******************************
%{
#include<stdio.h>
int s=0,c=0,w=0,special=0,l=0;
int count=1;
%}
%%
[ \t] {s++;}
[\n] { l++;}
[a-zA-Z0-9]+ {c+=yyleng;w++;fprintf(yyout,"%s",yytext);}
[@ # $ % ^ & * ( )] {special++; fprintf(yyout,"Special symbol found %s",yytext);}
. {ECHO;}
%%
int main()
{

Continue Reading

Program to label the tree for code generation.using Labeling Algorithm

Input:   Syntax Tree

Output: Labelled syntax tree [use any tree traversal method]

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

typedef struct node1
{
int lable;
char val;
struct node1 *left,*right;
}node;

node* create(int);


Continue Reading

Program for Implementation of Unification algorithm.



#include<stdio.h>
#include<conio.h>
int no_of_pred;
int no_of_arg[10];
int i,j;
char nouse;
char predicate[10];
char argument[10][10];

Continue Reading

Program for Implementation of Graph Coloring Algorithm

#include<stdio.h>
#include<conio.h>
#include<iostream.h>
int a, number, G[20][20], c[20];
void mcoloring(int p);
int nextvalue(int p);
void mcoloring(int p)

Continue Reading

C++ program for Implementation of MiniMax Algorithm.



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

int i,t, k=1,head=1;
int arr[10];
class node
{
  public:
            int data;
            int value;
            int Turn;
            int E;
            int kk;
            int path[10];
            int final[10];
            int childs;
            node *parent;
            node *child[10];
            node(int x)
              {
                        data=x;
                        value=-1;                     E=-1;    kk=1;
              }
};

class tree
 {
            node *root;

            void inorder1(node *T);
            void print1(node *T);
            node *create1();
            int findmax(int a[],int);
            int findmin(int a[],int);

            public:
            node *prev;
            tree() { root=NULL; root->parent=root;root->Turn=2;}
            void create() {root->parent=root;root->Turn=2;root=create1(); }
            void display(){inorder1(root);}
            void print(){print1(root);}

 };



 node * tree::create1()
  {
            node *p;
            int x;
            int  nchild=0;

            cout<<"\n Enter a data (unique number for designating the node) : ";
            cin >> x;

            p=new node(x);

            if(head==1)
            {
             p->parent=p;
             head=0;
            }
            else
            {
              p->parent=prev;
            }

             for( i=1;i<=10;i++)
                        {
                          p->child[i]=NULL;
                          p->child[i]->data=-1;
                          p->child[i]->parent=p;
               }


   if((p->parent->Turn)== 2)
                        p->Turn=1;
   else
                        p->Turn=2;
               for(i=1;i<=10;i++)
               {
                        p->path[i]=-1;
                        p->final[i]=-1;
               }

            cout<<"\n Enter the no of children of "<<x<<" :";
            cin >> nchild;


            p->childs=nchild;
            p->value=-1;
            p->kk=1;



                        if(nchild==0)
                        {
                                                cout<<"\n Enter the value of node "<<x<<" : ";
                                                cin>>(p->value);
                                                p->E=1;
                                                p->path[1]=p->data;
                                                for(i=2;i<=10;i++)
                                                p->path[i]=-1;


                        }

            for(i=1;i<=nchild;i++)
            {
            prev=p;
            cout<<"\nEnter child"<<i<<" of "<<x ;
            p->child[i]->parent=p;
            p->child[i]=create1();

            }
            return p;
  }


void tree::inorder1(node *T)
 {
            if(T!=NULL)
            {

                        cout<<"  "<<T->data;


                        for(int i=1;i<=(T->childs);i++)
                        {
                           if(i==1)
                                    k=T->kk;


                                    if(T->value==-1)
                                      inorder1(T->child[i]);
                        }

                        if((T->value!=-1) && (T->childs==0))
                        {
                                       node *p;
                                       p=T->parent;
                                       p->final[k]=T->value;
                                       k++;
                                                T->parent->kk=k;


                        }
                        if(T->value==-1)
                        {
                        int index;
                                                int trf=T->Turn;
                                                k=T->kk;

                                                for(t=1;t<=10;t++)
                                                            arr[t]=0;
                                                for(t=1;t<k;t++)
                                                {
                                                  arr[t]=T->final[t];
                                                }

                                                if(trf==2)
                                                 index=findmax(arr,k);
                                                 else
                                                 index=findmin(arr,k);
                                                 for(t=1;t<=10;t++)
                                                 {
                                                 if(T->child[index]->path[t] == -1)
                                                            break;
                                                 T->path[t]=T->child[index]->path[t];
                                                 }

                                                 T->path[t]=T->data;
                                                 T->E=1;
                                                 T->value=T->child[index]->value;
                                                 k=T->parent->kk;

                                                 T->parent->final[k]=T->value;
                                                 k++;
                                                 T->parent->kk=k;
                        }



            }
  }

void tree::print1(node *T)
{

            cout<<"\n\nActual Path of traversing is ";
            for(int i=1;i<=10;i++)
            {
            if(T->path[i]==-1)
                        break;
            cout<<(T->path[i])<<"  ";
            }
            cout<<"\nAssociated Cost will be "<<T->value;
}

int tree::findmax(int a[],int k)
{
int temp=-1;
int i,tindex;
for(i=1;i<k;i++)
{
            if(a[i]>temp)
            {
            temp=a[i];
            tindex=i;
            }
}

return tindex;
}

int tree::findmin(int a[],int k)
{
int temp=999;
int i,tindex;
for(i=1;i<k;i++)
{
            if(a[i]<temp)
            {
                        temp=a[i];
                        tindex=i;
            }
}

return tindex;
}

int main()
{
            tree  t1;
            node *p;
            int x,op;
            //clrscr();
            do
               {
                        cout<<"\n\n1)Create\n2)Display\n3)Quit";
                        cout <<"\nEnter Your Choice :";
                        cin>>op;
                        switch(op)
                           {
                                    case 1: t1.create();break;
                                    case 2: t1.display();
                                                            t1.print();
                                                            break;

                                    }
               }while(op!=3);

               getch();
}




Output :
1)Create
2)Display
3)Quit
Enter Your Choice :1

 Enter a data (unique number for designating the node) : 1

 Enter the no of children of 1 :2

Enter child1 of 1
 Enter a data (unique number for designating the node) : 2

 Enter the no of children of 2 :2

Enter child1 of 2
 Enter a data (unique number for designating the node) : 4

 Enter the no of children of 4 :0

 Enter the value of node 4 : 3

Enter child2 of 2
 Enter a data (unique number for designating the node) : 5

 Enter the no of children of 5 :0

 Enter the value of node 5 : 5

Enter child2 of 1
 Enter a data (unique number for designating the node) : 3

 Enter the no of children of 3 :3

Enter child1 of 3
 Enter a data (unique number for designating the node) : 6

 Enter the no of children of 6 :2

Enter child1 of 6
 Enter a data (unique number for designating the node) : 9

 Enter the no of children of 9 :2

Enter child1 of 9
 Enter a data (unique number for designating the node) : 13
Enter the no of children of 13 :0

 Enter the value of node 13 : 0

Enter child2 of 9
 Enter a data (unique number for designating the node) : 14

 Enter the no of children of 14 :0

 Enter the value of node 14 : 0
Enter child2 of 6
 Enter a data (unique number for designating the node) : 10

 Enter the no of children of 10 :0

 Enter the value of node 10 : 5

Enter child2 of 3
 Enter a data (unique number for designating the node) : 7

 Enter the no of children of 7 :2

Enter child1 of 7
 Enter a data (unique number for designating the node) : 11

 Enter the no of children of 11 :0

 Enter the value of node 11 : 7

Enter child2 of 7
 Enter a data (unique number for designating the node) : 12

 Enter the no of children of 12 :0

 Enter the value of node 12 : 8

Enter child3 of 3
 Enter a data (unique number for designating the node) : 8

 Enter the no of children of 8 :0

 Enter the value of node 8 : 4


1)Create
2)Display
3)Quit
Enter Your Choice :2
  1  2  4  5  3  6  9  13  14  10  7  11  12  8
Actual Path of traversing is 5  2  1
Associated Cost will be  5
1)Create
2)Display
3)Quit
Enter Your Choice :3

Continue Reading