SlideShare a Scribd company logo
IMPLEMENTATION OF QUEUE USING LINKED LIST

#include<iostream.h>
#include<process.h>
#include<conio.h>
class equeue
{
 struct node
 {
  int info;
  node *next;
 }*front,*rear;
public:equeue()
{
 front=rear=NULL;
}
 void insert(void);
 void deleted(void);
 void display(void);
};

void equeue::insert()
{
 node *temp=new node;
 cout<<"n Enter Value To Insert:";
 cin>>temp->info;
 temp->next=NULL;
 if(front==NULL)
 {
  front=rear=temp;
 }
 else
 {
  rear->next=temp;
  rear=rear->next;
 }
}

void equeue::deleted()
{
 if(front==NULL)
 {
  cout<<"n Queue Is Emptyn";
 }
 else
{
  if(front==rear)
  {
   cout<<"n Deleted Element Is :"<<front->info;
   front=rear=NULL;
  }
  else
  {
    node *temp=front;
    cout<<"n Deleted Element Is :"<<temp->info;
    front=front->next;
    delete(temp);
  }
 }
}

void equeue::display()
{
  if(front==NULL)
   cout<<"Queue Is Emptyn";
  else
  {
   node *t=front;
   while(t->next!=NULL)
   {
     cout<<t->info<<"n";
     t=t->next;
   }
   cout<<t->info;
 }
}

void main()
{
 equeue c;
 int ch;
 clrscr();
 while(1)
 {
  cout<<"n 1.Insertn 2.Deleten 3.Displayn 4.Exitn";
  cout<<"n Enter Your Choice:";
  cin>>ch;
  switch(ch)
  {
   case 1:c.insert();
break;
   case 2:c.deleted();
   break;
   case 3:c.display();
   break;
   case 4:exit(0);
   break;
   default:cout<<"n Enter The Right Choice";
  }
 }
}




OUTPUT:

1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice: 1
Enter the value to insert: 11

1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice: 1
Enter the value to insert:22

1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice: 1
Enter the value to insert:33

1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice: 3
11 22 33
1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice:2
Deleted Element is: 11

1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice:2
Deleted Element is: 22

1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice:2
Deleted Element is: 33

1.Insert
2.Delete
3.Display
4.Exit
Enter Your Choice:3
Queue is Empty
IMPLEMENTATION OF DOUBLE LINKED LIST

#include <iostream.h>
#include<MEMMGR.H>
#include<process.h>
#include<conio.h>
class dllist
{
 struct node
 {
 int value;
 struct node *next;
 struct node *prev;
 };
 struct node *start;
 public: dllist()
 {
  start=NULL;
  }
  void insertbegin(int value);
  void insertend(int value);
  void insertmiddle(int value,int nvalue);
  void deletebegin();
  void deleteend();
  void deletemiddle(int value);
  void display();
  };

void dllist::insertmiddle(int value,int nvalue)
         {
                 struct node *temp,*curr,*ncurr;
                 temp=(struct node*)new (struct node);
                 temp->value=value;
                 curr=start;
                 while(curr->value!=nvalue)
                 {
                  curr=curr->next;
                 }
              temp->prev=curr;
              temp->next=curr->next;
              curr->next=temp;
        }
void dllist::insertbegin(int value)
         {
                 struct node *temp;
                 temp=(struct node*)new (struct node);
                 temp->value=value;
                 if(start==NULL)
                 {
                          temp->prev=NULL;
                          temp->next=NULL;
                          start=temp;
                 }
                 else
                 {
                          temp->next=start;
                          temp->prev=NULL;
                          start=temp;

               }
        }

void dllist::insertend(int value)
        {
                 struct node *temp,*curr;
                 temp=(struct node *)new(struct node);
                 temp->value=value;
                 curr=start;
                 while(curr->next!=NULL)
                 {
                 curr=curr->next;
                 }
                 temp->prev=curr;
                 curr->next=temp;
                 temp->next=NULL;
        }

void dllist::deletebegin()
         {
           struct node *curr;
           curr=start;
           start=curr->next;
           start->prev=NULL;
           cout<<curr->value;
           free(curr);
         }
void dllist::deleteend()
{
        struct node *curr=start,*pcurr;
        while(curr->next!=NULL)
         {
         pcurr=curr;
         curr=curr->next;
         }
         pcurr->next=NULL;
         cout<<curr->value;
         free(curr);
}

void dllist::deletemiddle(int value)
{

       struct node *curr=start,*pcurr,*ncurr;
       pcurr=ncurr=start;
       while(curr->value!=value)
       {
       pcurr=curr;
       curr=curr->next;
       }
       ncurr=curr->next;
       pcurr->next=curr->next;
       ncurr->prev=curr->prev;
       cout<<"deleted element:"<<curr->value;
       free(curr);
}

void dllist::display()
{
        struct node *curr;
        curr=start;
        cout<<"nThe list is :n";
        if(curr==NULL)
         cout<<"list is empty";
         else
         {
         while(curr->next!=NULL)
                 {
                  cout<<curr->value<<"->";
                  curr=curr->next;
                 }
                 cout<<curr->value;
         }
}

void main()
{
int ch1,ch2,num,nd;
dllist st;
clrscr();
while(1)
{
 cout<<"n1.Insertn2.Deleten3.Displayn4.Exitn";
cin>>ch1;
switch(ch1)
{
 case 1:
     {
      cout<<"nInsert :n1.Beginningn2.Endn3.Middlen";
           cin>>ch2;
           switch(ch2)
           {
            case 1:
                  {
                   cout<<"enter the element:";
                   cin>>num;
                   st.insertbegin(num);
                   break;
                  }
            case 2:
                  {
                   cout<<"enter the element:";
                   cin>>num;
                   st.insertend(num);
                   break;
                  }
            case 3:
                  {
                   cout<<"enter the node after which to insert:";
                   cin>>nd;
                   cout<<"enter the element:";
                   cin>>num;
                   st.insertmiddle(num,nd);
                   break;
                  }
           default: cout<<"enter the correct choice";
         }
    break;
}
case 2:
    {
     cout<<"nDelete:n1.Beginningn2.Endn3.Middle";
         cin>>ch2;
         switch(ch2)
         {
          case 1:
                 {
                  cout<<"Deletion fron beginning:";
                  st.deletebegin();
                  break;
                 }
          case 2:
                 {
                  cout<<"Deletion from the end:";
                  st.deleteend();
                  break;
                 }
          case 3:
                 {
                  cout<<"enter the node to be deleted:";
                  cin>>nd;
                  st.deletemiddle(nd);
                  break;
                 }
         default: cout<<"enter the correct choice";
        }
        break;
    }
case 3:
    {
         st.display();
         break;

   }
case 4:exit(0);
default: cout<<"enter the correct choice";
}

}
}
OUTPUT:
1.Insert
2.Delete
3.Display
4.Exit
Enter your choice: 1

Insert:
1.Beginning
2.End
3.Middle
1
Enter the element:11

1.Insert
2.Delete
3.Display
4.Exit
Enter your choice:1

Insert:
1.Beginning
2.End
3.Middle
2
Enter the element:22

1.Insert
2.Delete
3.Display
4.Exit
Enter your choice:1

Insert:
1.Beginning
2.End
3.Middle
3
Enter the node after which to insert:11
Enter the element:33

1.Insert
2.Delete
3.Display
4.Exit
Enter your choice:3
11->33->22

1.Insert
2.Delete
3.Display
4.Exit
Enter your choice:2

Delete:
1.Beginning
2.End
3.Middle
3
Enter the node to be deleted: 33
Deleted element :33

1.Insert
2.Delete
3.Display
4.Exit
Enter your choice:2

Delete:
1.Beginning
2.End
3.Middle
1
Deletion from the beginning 11

 1.Insert
2.Delete
3.Display
4.Exit
Enter your choice:2

Delete:
1.Beginning
2.End
3.Middle
2
Deletion from the end 22
IMPLEMNTATION OF BINARY SEARCH TREE NON RECURSIVE
                           TRAVERSAL
#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<malloc.h>
#include<process.h>

struct bstree
{
        int data;
        struct bstree*left;
        struct bstree*right;
}*root=NULL;

class bst
  {
    private:

   public :
      void insert(bstree *,int);
      void inorder_non_rec(bstree*);
      void preorder_non_rec(bstree*);
      void postorder_non_rec(bstree*);
      };

class stack
 {
   int top;
   bstree *stackel[20];
   public:
     stack()
          {
            top=-1;
          }
        void push(bstree *);
        bstree* pop();
        int empty()
        {
          if(top==-1)
             return(1);
          else
          return(0);
        }
 };
class stack_int
 {
   int top;
   int stack_int[20];
   public:
    stack_int()
          {
            top=-1;
          }
    void push(int flag);
    int pop();
    int empty_int()
         {
           if(top==-1)
             return(1);
           else
             return(0);
         }
   };

void stack_int::push(int flag)
   {
     stack_int[++top]=flag;
   }
int stack_int::pop()
   {
     return(stack_int[top--]);
   }

void stack::push(bstree *node)
 {
   stackel[++top]=node;
 }

bstree *stack::pop()
 {
   return(stackel[top--]);
 }

void bst :: insert(struct bstree*head,int val)
{
       struct bstree *temp1,*temp2;
       if(head == NULL)
       {
head=(struct bstree*)malloc(sizeof(struct bstree));
              root=head;
              head->data=val;
              head->left=NULL;
              head->right=NULL;
       }
       else
       {
               temp1=head;
               while(temp1 != NULL)
               {
                      temp2=temp1;
                      if(temp1->data > val)
                             temp1=temp1->left;
                      else
                             temp1=temp1->right;
               }
              if(temp2->data > val)
              {
                      temp2->left=(struct bstree*)malloc(sizeof(struct bstree));
                      temp2=temp2->left;
                      temp2->data=val;
                      temp2->left=NULL;
                      temp2->right=NULL;
              }
              else
              {
                      temp2->right=(struct bstree*)malloc(sizeof(struct bstree));
                      temp2=temp2->right;
                      temp2->data=val;
                      temp2->left=NULL;
                      temp2->right=NULL;
              }
       }
}

void bst::postorder_non_rec(bstree *root)
  {
   stack stk;
   stack_int stk1;
   int flag;
   bstree *temp=root;
        do
          {
            if(temp!=NULL)
{
               stk.push(temp);
               stk1.push(1);
               temp=temp->left;
          }
        else
          {
               if(stk.empty())
               break;
               temp=stk.pop();
               flag=stk1.pop();
               if(flag==2)
                 {
                   cout<<temp->data;
                   temp=NULL;
                 }
               else
                 {
                   stk.push(temp);
                   stk1.push(2);
                   temp=temp->right;
                 }
          }
        }while(1);
  }

void bst::preorder_non_rec(bstree *root)
  {
       stack stk;
       bstree *temp=root;
       stk.push(temp);
         while(!stk.empty())
           {
               temp=stk.pop();
               if(temp!=NULL)
                 {
                   cout<<temp->data<<" ";
                   stk.push(temp->right);
                   stk.push(temp->left);
                 }
           }
  }
void bst::inorder_non_rec(bstree *root)
  {
    stack stk;
    bstree *temp;
    if(root!=NULL)
         {
            temp=root;
            do
              {
                 while(temp!=NULL)
                   {
                     stk.push(temp);
                     temp=temp->left;
                   }
                 if(!stk.empty())
                   {
                     temp=stk.pop();
                     cout<<temp->data<<" ";
                     temp=temp->right;
                   }
                 else
                   break;
              }while(1);
         }
    else
      cout<<"Empty tree";
}

void main()
  {
      int info,opt;
      char choice;
      clrscr();
      bst b;
      do
        {
           cout<<"n 1-Insert n 2-Inorder n 3-Preordern 4-Postord n 5. Exitn";
           cout<<"n ENTER YOUR CHOICE:";
           cin>>opt;
              switch(opt)
              {
                     case 1: cout<<"n enter the number :";
                             cin>>info;
                             b.insert(root,info);
                             break;
case 2: cout<<"n Inorder n non recursive display is:";
                              b.inorder_non_rec(root);
                              break;
                      case 3: cout<<"nPreorder n non recursive display is:";
                              b.preorder_non_rec(root);
                              break;
                       case 4: cout<<"n Post order n non recursive display is:";
                               b.postorder_non_rec(root);
                               break;
                      case 5: exit(0);
           }
    }while(1);
}



OUTPUT

         1.Insert
         2.Inorder
         3.Preorder
         4.Postorder
         5.Exit
         Enter your choice: 1
         Enter the element: 2

         1.Insert
         2.Inorder
         3.Preorder
         4.Postorder
         5.Exit
         Enter your choice: 1
         Enter the element: 67

         1.Insert
         2.Inorder
         3.Preorder
         4.Postorder
         5.Exit
         Enter your choice: 1
         Enter the element: 12

         1.Insert
         2.Inorder
         3.Preorder
4.Postorder
5.Exit
Enter your choice: 1
Enter the element: 45

1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 1
Enter the element: 74

1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 1
Enter the element: 21

1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 2
In order
Non recursive display: 2 12 21 45 67 74
1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 3
Pre order
Non recursive display: 2 67 12 45 21 74
1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 4
Post order
Non recursive display: 21 45 12 74 67 2
IMPLEMENTATION OF BINARY SEARCH TREE RECURSIVE TRAVERSAL

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
#include<malloc.h>
#include<process.h>

struct bstree
{
        int data;
        struct bstree*left;
        struct bstree*right;
}*root=NULL;

class bst
  {
    private:

   public :
      void insert(bstree *,int);
      void inorder(bstree*);
      void postorder(bstree *);
      void preorder(bstree *);
      };

class stack
 {
   int top;
   bstree *stackel[20];
   public:
     stack()
          {
            top=-1;
          }
        void push(bstree *);
        bstree* pop();
        int empty()
        {
          if(top==-1)
             return(1);
          else
          return(0);
        }
 };
class stack_int
 {
   int top;
   int stack_int[20];
   public:
    stack_int()
          {
            top=-1;
          }
    void push(int flag);
    int pop();
    int empty_int()
         {
           if(top==-1)
             return(1);
           else
             return(0);
         }
   };

void stack_int::push(int flag)
   {
     stack_int[++top]=flag;
   }
int stack_int::pop()
   {
     return(stack_int[top--]);
   }

void stack::push(bstree *node)
 {
   stackel[++top]=node;
 }

bstree *stack::pop()
 {
   return(stackel[top--]);
 }

void bst :: insert(struct bstree*head,int val)
{
       struct bstree *temp1,*temp2;
       if(head == NULL)
       {
head=(struct bstree*)malloc(sizeof(struct bstree));
               root=head;
               head->data=val;
               head->left=NULL;
               head->right=NULL;
       }
       else
       {
                temp1=head;
                while(temp1 != NULL)
                {
                       temp2=temp1;
                       if(temp1->data > val)
                              temp1=temp1->left;
                       else
                              temp1=temp1->right;
                }
               if(temp2->data > val)
               {
                       temp2->left=(struct bstree*)malloc(sizeof(struct bstree));
                       temp2=temp2->left;
                       temp2->data=val;
                       temp2->left=NULL;
                       temp2->right=NULL;
               }
               else
               {
                       temp2->right=(struct bstree*)malloc(sizeof(struct bstree));
                       temp2=temp2->right;
                       temp2->data=val;
                       temp2->left=NULL;
                       temp2->right=NULL;
               }
       }
}

void bst :: postorder(struct bstree*head)
{
       if( head != NULL)
       {
                postorder(head->left);
                postorder(head->right);
                cout<<head->data;
       }
}
void bst :: preorder(struct bstree*head)
{
       if( head != NULL)
       {
                cout<<head->data;
                preorder(head->left);
                preorder(head->right);
       }
}


void bst::inorder(bstree *root)
  {
    stack stk;
    bstree *temp;
         temp=root;
    if(temp!=NULL)
         {
           inorder(temp->left);
           cout<<temp->data;
           inorder(temp->right);
         }
}

void main()
  {
      int info,opt;
      char choice;
      clrscr();
      bst b;
      do
        {
           cout<<"n 1-Insert n 2-Inorder n 3-Preordern 4-Postorder n 5. Exitn";
           cout<<"n ENTER YOUR CHOICE:";
           cin>>opt;
              switch(opt)
              {
                     case 1: cout<<"n enter the number :";
                             cin>>info;
                             b.insert(root,info);
                             break;
                     case 2:cout<<"n recursive display is:";
                             b.inorder(root);
                             break;
case 3:cout<<"n recursive display is:";
                            b.preorder(root);
                            break;
                     case 4:cout<<"n recursive display is:";
                             b.postorder(root);
                             break;
                    case 5: exit(0);
           }
    }while(1);
}



OUTPUT

         1.Insert
         2.Inorder
         3.Preorder
         4.Postorder
         5.Exit
         Enter your choice: 1
         Enter the element: 2

         1.Insert
         2.Inorder
         3.Preorder
         4.Postorder
         5.Exit
         Enter your choice: 1
         Enter the element: 67

         1.Insert
         2.Inorder
         3.Preorder
         4.Postorder
         5.Exit
         Enter your choice: 1
         Enter the element: 12

         1.Insert
         2.Inorder
         3.Preorder
         4.Postorder
         5.Exit
         Enter your choice: 1
Enter the element: 45

1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 1
Enter the element: 74

1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 1
Enter the element: 21

1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 2
In order
Recursive display: 2 12 21 45 67 74

1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 3
Pre order
Recursive display: 2 67 12 45 21 74

1.Insert
2.Inorder
3.Preorder
4.Postorder
5.Exit
Enter your choice: 4
Post order
Recursive display: 21 45 12 74 67 2
IMPLEMENTATION OF Breadth First Search

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int cost[10][10],i,j,k,n,qu[10],front,rare,v,visit[10],visited[10];

main()
{
int m;
cout <<"enter no of vertices";
cin >> n;
cout <<"enter no of edges";
cin >> m;
cout <<"nEDGES n";
for(k=1;k<=m;k++)
{
cin >>i>>j;
cost[i][j]=1;
}

cout <<"enter initial vertex";
cin >>v;
cout <<"Visitied verticesn";
cout << v;
visited[v]=1;
k=1;
while(k<n)
{
for(j=1;j<=n;j++)
if(cost[v][j]!=0 && visited[j]!=1 && visit[j]!=1)
{
visit[j]=1;
qu[rare++]=j;
}
v=qu[front++];
cout<<v << " ";
k++;
visit[v]=0; visited[v]=1;
}
}
OUTPUT:
Enter the no of vertices: 9
Enter the no of edges:9
EDGES
   1       2
   2       3
   1       5
   1       4
   4       7
   7       8
   8       9
   2       6
   5       7
   Enter initial vertex: 1

   Visited vertices
                              1   2 4 5 3 6 7 8 9
IMPLEMENTATION OF Depth First Search

#include<iostream.h>
#include<conio.h>
#include<stdlib.h>
int cost[10][10],i,j,k,n,stk[10],top,v,visit[10],visited[10];

main()
{
int m;
cout <<"enterno of vertices";
cin >> n;
cout <<"ente no of edges";
cin >> m;
cout <<"nEDGES n";
for(k=1;k<=m;k++)
{
cin >>i>>j;
cost[i][j]=1;
}

cout <<"enter initial vertex";
cin >>v;
cout <<" VISITED VERTICES";
cout << v <<" ";
visited[v]=1;
k=1;
while(k<n)
{
for(j=n;j>=1;j--)
if(cost[v][j]!=0 && visited[j]!=1 && visit[j]!=1)
{
visit[j]=1;
stk[top]=j;
top++;
}
v=stk[--top];
cout<<v << " ";
k++;
visit[v]=0; visited[v]=1;
}
}
OUTPUT:

Enter the no of vertices: 9
Enter the no of edges:9
EDGES
   1       2
   2       3
   1       5
   1       4
   4       7
   7       8
   8       9
   2       6
   5       7
   Enter initial vertex: 1

   Visited vertices
   1 2 3 6 4 7 8 9 5
IMPLEMENTATION OF HEAP SORT

#include<iostream.h>
#include<conio.h>
#include<stdio.h>
void heapify(int a[],int i);
void buildheap(int a[]);
void heapsort(int a[]);
int n;
void main()
{
int a[100];
clrscr();
cout<<"enter n valuen";
cin>>n;
int l=n;
cout<<"enter array of elementsn";
for(int i=0;i<n;i++)
cin>>a[i];
heapsort(a);
cout<<"the sorted list of elements are:"<<endl;
for(i=0;i<l;i++)
cout<<a[i]<<endl;
getch();
}
void heapify(int a[],int i)
{
int l,r,large;
l=2*i+1;
r=2*i+2;
if(l<n&&a[l]>=a[i])
large=1;
else
large=i;
if(r<n&&a[r]>=a[large])
large=r;
if(i!=large)
{
int t;
t=a[i];
a[i]=a[large];
a[large]=t;
heapify(a,large);
}
}
void buildheap(int a[])
{
 int i;
 for(i=(n/2)-1;i>=0;i--)
 heapify(a,i);
 }
void heapsort(int a[])
 {
 buildheap(a);
 for(int i=n-1;i>=1;i--)
 {
 int t;
 t=a[0];
 a[0]=a[i];
 a[i]=t;
 n--;
 heapify(a,0);
 }
 }




OUTPUT:
enter n value
4
enter array of elements
5
6
3
2
the sorted list of elements are:
2
3
5
6
IMPLEMENTATION OF PROGRAM TO CONVERT INFIX TO POSTFIX FORM

#include<iostream.h>
#include<conio.h>
#include<string.h>
#define MAXSIZE 100
class STACK_ARRAY
{
int stack[MAXSIZE];
int Top;
public:
STACK_ARRAY()
{
Top=-1;
}
void push(char);
char pop();
int prec(char);
void Infix_Postfix();
};
void STACK_ARRAY::push(char item)
{
if (Top == MAXSIZE-1)
{
cout<<"nThe Stack Is Full";
getch();
}
else
stack[++Top]=item;
}
char STACK_ARRAY::pop()
{
char item='#';
if (Top == -1)
cout<<"nThe Stack Is Empty. Invalid Infix expression";
else
item=stack[Top--];
return(item);
}
int STACK_ARRAY::prec(char symbol)
{
switch(symbol)
{
case '(':
return(1);
case ')':
return(2);
case '+':
case '-':
return(3);
case '*':
case '/':
case '%':
return(4);
case '^':
return(5);
default:
return(0);
}
}
void STACK_ARRAY::Infix_Postfix()
{
int len,priority;
char infix[MAXSIZE],postfix[MAXSIZE],ch;
cout<<"nnEnter the infix expression = ";
cin>>infix;
len=strlen(infix);
infix[len++]=')';
push('(');
for(int i=0,j=0;i<len;i++)
{
switch(prec(infix[i]))
{
case 1:
push(infix[i]);
break;
case 2:
ch=pop();
while(ch != '(')
{
postfix[j++]=ch;
ch=pop();
}
break;
case 3:
ch=pop();
while(prec(ch) >= 3)
{
postfix[j++]=ch;
ch=pop();
}
push(ch);
push(infix[i]);
break;
case 4:
ch=pop();
while(prec(ch) >= 4)
{

postfix[j++]=ch;
ch=pop();
}
push(ch);
push(infix[i]);
break;
case 5:
ch=pop();
while(prec(ch) == 5)
{
postfix[j++]=ch;
ch=pop();
}
push(ch);
push(infix[i]);
break;
default:
postfix[j++]=infix[i];
break;
}
}
cout<<"nThe Postfix expression is =";
for(i=0;i<j;i++)
cout<<postfix[i];
}
void main()
{
char choice;
STACK_ARRAY ip;
clrscr();
do
{
clrscr();
ip.Infix_Postfix();
cout<<"nnDo you want to continue (Y/y) =";
cin>>choice;
}while(choice == 'Y' || choice == 'y');
}




OUTPUT:

Enter the infix expression:
A+B
The postfix expression is
AB+
Do you wish to continue(Y/y)= y

Enter the infix expression:
A+(B-C)
The postfix expression is
ABC-+
Do you wish to continue(Y/y)=n

More Related Content

What's hot

C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
Farhan Ab Rahman
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
Farhan Ab Rahman
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
Farhan Ab Rahman
 
Oop1
Oop1Oop1
Polymorphism
PolymorphismPolymorphism
Polymorphism
mohamed sikander
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
Darwin Durand
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
Farhan Ab Rahman
 
Ss
SsSs
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
Farhan Ab Rahman
 
Cquestions
Cquestions Cquestions
Cquestions
mohamed sikander
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
The Software House
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
Alfonso Peletier
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
Farhan Ab Rahman
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python Programmers
Appier
 
Container adapters
Container adaptersContainer adapters
Container adapters
mohamed sikander
 
C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
Mohammad Shaker
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
Mahmoud Samir Fayed
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
aleks-f
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
Binary Studio
 
Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
Ovidiu Farauanu
 

What's hot (20)

C++ TUTORIAL 10
C++ TUTORIAL 10C++ TUTORIAL 10
C++ TUTORIAL 10
 
C++ TUTORIAL 3
C++ TUTORIAL 3C++ TUTORIAL 3
C++ TUTORIAL 3
 
C++ TUTORIAL 5
C++ TUTORIAL 5C++ TUTORIAL 5
C++ TUTORIAL 5
 
Oop1
Oop1Oop1
Oop1
 
Polymorphism
PolymorphismPolymorphism
Polymorphism
 
VISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLEVISUALIZAR REGISTROS EN UN JTABLE
VISUALIZAR REGISTROS EN UN JTABLE
 
C++ TUTORIAL 9
C++ TUTORIAL 9C++ TUTORIAL 9
C++ TUTORIAL 9
 
Ss
SsSs
Ss
 
C++ TUTORIAL 1
C++ TUTORIAL 1C++ TUTORIAL 1
C++ TUTORIAL 1
 
Cquestions
Cquestions Cquestions
Cquestions
 
Developer Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duoDeveloper Experience i TypeScript. Najbardziej ikoniczne duo
Developer Experience i TypeScript. Najbardziej ikoniczne duo
 
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic LabsTypeScript - All you ever wanted to know - Tech Talk by Epic Labs
TypeScript - All you ever wanted to know - Tech Talk by Epic Labs
 
C++ TUTORIAL 8
C++ TUTORIAL 8C++ TUTORIAL 8
C++ TUTORIAL 8
 
Basic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python ProgrammersBasic C++ 11/14 for Python Programmers
Basic C++ 11/14 for Python Programmers
 
Container adapters
Container adaptersContainer adapters
Container adapters
 
C++ L08-Classes Part1
C++ L08-Classes Part1C++ L08-Classes Part1
C++ L08-Classes Part1
 
The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184The Ring programming language version 1.5.3 book - Part 25 of 184
The Ring programming language version 1.5.3 book - Part 25 of 184
 
Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013Dynamic C++ ACCU 2013
Dynamic C++ ACCU 2013
 
Academy PRO: ES2015
Academy PRO: ES2015Academy PRO: ES2015
Academy PRO: ES2015
 
Bind me if you can
Bind me if you canBind me if you can
Bind me if you can
 

Viewers also liked

Neil Armstrong Hall of Engineering
Neil Armstrong Hall of EngineeringNeil Armstrong Hall of Engineering
Neil Armstrong Hall of Engineering
seunghoon91
 
South park middle school
South park middle schoolSouth park middle school
South park middle school
hvolrie
 
Ds program-print
Ds program-printDs program-print
Ds program-print
Chaitanya Kn
 
Dbms 2
Dbms 2Dbms 2
Dbms 2
Chaitanya Kn
 
Presentation1
Presentation1Presentation1
Presentation1
Chaitanya Kn
 
Texas STaR Chart Powerpoint
Texas STaR Chart PowerpointTexas STaR Chart Powerpoint
Texas STaR Chart Powerpoint
stevetaylor18
 
South park middle school
South park middle schoolSouth park middle school
South park middle school
hvolrie
 
Week 4 - Technology Action Plan
Week 4 - Technology Action PlanWeek 4 - Technology Action Plan
Week 4 - Technology Action Plan
stevetaylor18
 
Dbms print
Dbms printDbms print
Dbms print
Chaitanya Kn
 
Fantastic trip by nasa
Fantastic trip by nasaFantastic trip by nasa
Fantastic trip by nasa
Chaitanya Kn
 

Viewers also liked (10)

Neil Armstrong Hall of Engineering
Neil Armstrong Hall of EngineeringNeil Armstrong Hall of Engineering
Neil Armstrong Hall of Engineering
 
South park middle school
South park middle schoolSouth park middle school
South park middle school
 
Ds program-print
Ds program-printDs program-print
Ds program-print
 
Dbms 2
Dbms 2Dbms 2
Dbms 2
 
Presentation1
Presentation1Presentation1
Presentation1
 
Texas STaR Chart Powerpoint
Texas STaR Chart PowerpointTexas STaR Chart Powerpoint
Texas STaR Chart Powerpoint
 
South park middle school
South park middle schoolSouth park middle school
South park middle school
 
Week 4 - Technology Action Plan
Week 4 - Technology Action PlanWeek 4 - Technology Action Plan
Week 4 - Technology Action Plan
 
Dbms print
Dbms printDbms print
Dbms print
 
Fantastic trip by nasa
Fantastic trip by nasaFantastic trip by nasa
Fantastic trip by nasa
 

Similar to Ds 2 cycle

#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
harihelectronicspune
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
Elavarasi K
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
teyaj1
 
Snake.c
Snake.cSnake.c
Snake.c
Vijay Singh
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
kostikjaylonshaewe47
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
aathiauto
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
KUNALHARCHANDANI1
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
Sarmad Baloch
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
anupambedcovers
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
lakshmijewellery
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
fantoosh1
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
Ankit Gupta
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
feelinggift
 
Need help getting past an error in C++! I have all my code pasted down.docx
Need help getting past an error in C++! I have all my code pasted down.docxNeed help getting past an error in C++! I have all my code pasted down.docx
Need help getting past an error in C++! I have all my code pasted down.docx
Jason0x0Scottw
 
C program
C programC program
C program
Komal Singh
 
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
galagirishp
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
Pradeep Kumar Reddy Reddy
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
Lakshmi Sarvani Videla
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
Lakshmi Sarvani Videla
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
forladies
 

Similar to Ds 2 cycle (20)

#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf#includeiostream #includecstdio #includecstdlib using na.pdf
#includeiostream #includecstdio #includecstdlib using na.pdf
 
Linked list imp of list
Linked list imp of listLinked list imp of list
Linked list imp of list
 
Lab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docxLab Week 2 Game Programming.docx
Lab Week 2 Game Programming.docx
 
Snake.c
Snake.cSnake.c
Snake.c
 
This is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdfThis is a c++ binary search program I worked so far but still cant g.pdf
This is a c++ binary search program I worked so far but still cant g.pdf
 
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdfDoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
DoublyList-cpp- #include -DoublyList-h- using namespace std- void Doub.pdf
 
#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf#includeiostream#includecstdio#includecstdlibusing names.pdf
#includeiostream#includecstdio#includecstdlibusing names.pdf
 
Implement of c &amp; its coding programming by sarmad baloch
Implement of c &amp; its coding  programming by sarmad balochImplement of c &amp; its coding  programming by sarmad baloch
Implement of c &amp; its coding programming by sarmad baloch
 
C++ Program to Implement Singly Linked List #includei.pdf
  C++ Program to Implement Singly Linked List  #includei.pdf  C++ Program to Implement Singly Linked List  #includei.pdf
C++ Program to Implement Singly Linked List #includei.pdf
 
#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf#include iostream #includestdlib.h using namespace std;str.pdf
#include iostream #includestdlib.h using namespace std;str.pdf
 
In C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdfIn C++ I need help with this method that Im trying to write fillLi.pdf
In C++ I need help with this method that Im trying to write fillLi.pdf
 
program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)program on string in java Lab file 2 (3-year)
program on string in java Lab file 2 (3-year)
 
How do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdfHow do you stop infinite loop Because I believe that it is making a.pdf
How do you stop infinite loop Because I believe that it is making a.pdf
 
Need help getting past an error in C++! I have all my code pasted down.docx
Need help getting past an error in C++! I have all my code pasted down.docxNeed help getting past an error in C++! I have all my code pasted down.docx
Need help getting past an error in C++! I have all my code pasted down.docx
 
C program
C programC program
C program
 
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdfincludestdio.h #includestdlib.h int enqueue(struct node ,.pdf
includestdio.h #includestdlib.h int enqueue(struct node ,.pdf
 
Dsprograms(2nd cse)
Dsprograms(2nd cse)Dsprograms(2nd cse)
Dsprograms(2nd cse)
 
DataStructures notes
DataStructures notesDataStructures notes
DataStructures notes
 
Solutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structuresSolutionsfor co2 C Programs for data structures
Solutionsfor co2 C Programs for data structures
 
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdfI need to fill-in TODOs in .cpp file and in .h file Could some.pdf
I need to fill-in TODOs in .cpp file and in .h file Could some.pdf
 

More from Chaitanya Kn

Black box-software-testing-douglas-hoffman2483
Black box-software-testing-douglas-hoffman2483Black box-software-testing-douglas-hoffman2483
Black box-software-testing-douglas-hoffman2483
Chaitanya Kn
 
Nano tech
Nano techNano tech
Nano tech
Chaitanya Kn
 
Jpdcs1 data leakage detection
Jpdcs1 data leakage detectionJpdcs1 data leakage detection
Jpdcs1 data leakage detection
Chaitanya Kn
 
Jpdcs1(data lekage detection)
Jpdcs1(data lekage detection)Jpdcs1(data lekage detection)
Jpdcs1(data lekage detection)
Chaitanya Kn
 
(Cse cs) ads programs list
(Cse  cs) ads programs list(Cse  cs) ads programs list
(Cse cs) ads programs list
Chaitanya Kn
 
Testing primer
Testing primerTesting primer
Testing primer
Chaitanya Kn
 
Stm unit1
Stm unit1Stm unit1
Stm unit1
Chaitanya Kn
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
Chaitanya Kn
 
Stop complaining
Stop complainingStop complaining
Stop complaining
Chaitanya Kn
 
God doesn
God doesnGod doesn
God doesn
Chaitanya Kn
 
Os 2 cycle
Os 2 cycleOs 2 cycle
Os 2 cycle
Chaitanya Kn
 

More from Chaitanya Kn (11)

Black box-software-testing-douglas-hoffman2483
Black box-software-testing-douglas-hoffman2483Black box-software-testing-douglas-hoffman2483
Black box-software-testing-douglas-hoffman2483
 
Nano tech
Nano techNano tech
Nano tech
 
Jpdcs1 data leakage detection
Jpdcs1 data leakage detectionJpdcs1 data leakage detection
Jpdcs1 data leakage detection
 
Jpdcs1(data lekage detection)
Jpdcs1(data lekage detection)Jpdcs1(data lekage detection)
Jpdcs1(data lekage detection)
 
(Cse cs) ads programs list
(Cse  cs) ads programs list(Cse  cs) ads programs list
(Cse cs) ads programs list
 
Testing primer
Testing primerTesting primer
Testing primer
 
Stm unit1
Stm unit1Stm unit1
Stm unit1
 
Unix lab manual
Unix lab manualUnix lab manual
Unix lab manual
 
Stop complaining
Stop complainingStop complaining
Stop complaining
 
God doesn
God doesnGod doesn
God doesn
 
Os 2 cycle
Os 2 cycleOs 2 cycle
Os 2 cycle
 

Recently uploaded

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
taiba qazi
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
Nicholas Montgomery
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
Ashokrao Mane college of Pharmacy Peth-Vadgaon
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
RitikBhardwaj56
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
Nicholas Montgomery
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
thanhdowork
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
Kavitha Krishnan
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
heathfieldcps1
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
mulvey2
 

Recently uploaded (20)

Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
DRUGS AND ITS classification slide share
DRUGS AND ITS classification slide shareDRUGS AND ITS classification slide share
DRUGS AND ITS classification slide share
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
writing about opinions about Australia the movie
writing about opinions about Australia the moviewriting about opinions about Australia the movie
writing about opinions about Australia the movie
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.Types of Herbal Cosmetics its standardization.
Types of Herbal Cosmetics its standardization.
 
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...The simplified electron and muon model, Oscillating Spacetime: The Foundation...
The simplified electron and muon model, Oscillating Spacetime: The Foundation...
 
Film vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movieFilm vocab for eal 3 students: Australia the movie
Film vocab for eal 3 students: Australia the movie
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
A Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptxA Survey of Techniques for Maximizing LLM Performance.pptx
A Survey of Techniques for Maximizing LLM Performance.pptx
 
Assessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptxAssessment and Planning in Educational technology.pptx
Assessment and Planning in Educational technology.pptx
 
The basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptxThe basics of sentences session 6pptx.pptx
The basics of sentences session 6pptx.pptx
 
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptxC1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
C1 Rubenstein AP HuG xxxxxxxxxxxxxx.pptx
 

Ds 2 cycle

  • 1. IMPLEMENTATION OF QUEUE USING LINKED LIST #include<iostream.h> #include<process.h> #include<conio.h> class equeue { struct node { int info; node *next; }*front,*rear; public:equeue() { front=rear=NULL; } void insert(void); void deleted(void); void display(void); }; void equeue::insert() { node *temp=new node; cout<<"n Enter Value To Insert:"; cin>>temp->info; temp->next=NULL; if(front==NULL) { front=rear=temp; } else { rear->next=temp; rear=rear->next; } } void equeue::deleted() { if(front==NULL) { cout<<"n Queue Is Emptyn"; } else
  • 2. { if(front==rear) { cout<<"n Deleted Element Is :"<<front->info; front=rear=NULL; } else { node *temp=front; cout<<"n Deleted Element Is :"<<temp->info; front=front->next; delete(temp); } } } void equeue::display() { if(front==NULL) cout<<"Queue Is Emptyn"; else { node *t=front; while(t->next!=NULL) { cout<<t->info<<"n"; t=t->next; } cout<<t->info; } } void main() { equeue c; int ch; clrscr(); while(1) { cout<<"n 1.Insertn 2.Deleten 3.Displayn 4.Exitn"; cout<<"n Enter Your Choice:"; cin>>ch; switch(ch) { case 1:c.insert();
  • 3. break; case 2:c.deleted(); break; case 3:c.display(); break; case 4:exit(0); break; default:cout<<"n Enter The Right Choice"; } } } OUTPUT: 1.Insert 2.Delete 3.Display 4.Exit Enter Your Choice: 1 Enter the value to insert: 11 1.Insert 2.Delete 3.Display 4.Exit Enter Your Choice: 1 Enter the value to insert:22 1.Insert 2.Delete 3.Display 4.Exit Enter Your Choice: 1 Enter the value to insert:33 1.Insert 2.Delete 3.Display 4.Exit Enter Your Choice: 3 11 22 33
  • 4. 1.Insert 2.Delete 3.Display 4.Exit Enter Your Choice:2 Deleted Element is: 11 1.Insert 2.Delete 3.Display 4.Exit Enter Your Choice:2 Deleted Element is: 22 1.Insert 2.Delete 3.Display 4.Exit Enter Your Choice:2 Deleted Element is: 33 1.Insert 2.Delete 3.Display 4.Exit Enter Your Choice:3 Queue is Empty
  • 5. IMPLEMENTATION OF DOUBLE LINKED LIST #include <iostream.h> #include<MEMMGR.H> #include<process.h> #include<conio.h> class dllist { struct node { int value; struct node *next; struct node *prev; }; struct node *start; public: dllist() { start=NULL; } void insertbegin(int value); void insertend(int value); void insertmiddle(int value,int nvalue); void deletebegin(); void deleteend(); void deletemiddle(int value); void display(); }; void dllist::insertmiddle(int value,int nvalue) { struct node *temp,*curr,*ncurr; temp=(struct node*)new (struct node); temp->value=value; curr=start; while(curr->value!=nvalue) { curr=curr->next; } temp->prev=curr; temp->next=curr->next; curr->next=temp; }
  • 6. void dllist::insertbegin(int value) { struct node *temp; temp=(struct node*)new (struct node); temp->value=value; if(start==NULL) { temp->prev=NULL; temp->next=NULL; start=temp; } else { temp->next=start; temp->prev=NULL; start=temp; } } void dllist::insertend(int value) { struct node *temp,*curr; temp=(struct node *)new(struct node); temp->value=value; curr=start; while(curr->next!=NULL) { curr=curr->next; } temp->prev=curr; curr->next=temp; temp->next=NULL; } void dllist::deletebegin() { struct node *curr; curr=start; start=curr->next; start->prev=NULL; cout<<curr->value; free(curr); } void dllist::deleteend()
  • 7. { struct node *curr=start,*pcurr; while(curr->next!=NULL) { pcurr=curr; curr=curr->next; } pcurr->next=NULL; cout<<curr->value; free(curr); } void dllist::deletemiddle(int value) { struct node *curr=start,*pcurr,*ncurr; pcurr=ncurr=start; while(curr->value!=value) { pcurr=curr; curr=curr->next; } ncurr=curr->next; pcurr->next=curr->next; ncurr->prev=curr->prev; cout<<"deleted element:"<<curr->value; free(curr); } void dllist::display() { struct node *curr; curr=start; cout<<"nThe list is :n"; if(curr==NULL) cout<<"list is empty"; else { while(curr->next!=NULL) { cout<<curr->value<<"->"; curr=curr->next; } cout<<curr->value; }
  • 8. } void main() { int ch1,ch2,num,nd; dllist st; clrscr(); while(1) { cout<<"n1.Insertn2.Deleten3.Displayn4.Exitn"; cin>>ch1; switch(ch1) { case 1: { cout<<"nInsert :n1.Beginningn2.Endn3.Middlen"; cin>>ch2; switch(ch2) { case 1: { cout<<"enter the element:"; cin>>num; st.insertbegin(num); break; } case 2: { cout<<"enter the element:"; cin>>num; st.insertend(num); break; } case 3: { cout<<"enter the node after which to insert:"; cin>>nd; cout<<"enter the element:"; cin>>num; st.insertmiddle(num,nd); break; } default: cout<<"enter the correct choice"; } break;
  • 9. } case 2: { cout<<"nDelete:n1.Beginningn2.Endn3.Middle"; cin>>ch2; switch(ch2) { case 1: { cout<<"Deletion fron beginning:"; st.deletebegin(); break; } case 2: { cout<<"Deletion from the end:"; st.deleteend(); break; } case 3: { cout<<"enter the node to be deleted:"; cin>>nd; st.deletemiddle(nd); break; } default: cout<<"enter the correct choice"; } break; } case 3: { st.display(); break; } case 4:exit(0); default: cout<<"enter the correct choice"; } } }
  • 10. OUTPUT: 1.Insert 2.Delete 3.Display 4.Exit Enter your choice: 1 Insert: 1.Beginning 2.End 3.Middle 1 Enter the element:11 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:1 Insert: 1.Beginning 2.End 3.Middle 2 Enter the element:22 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:1 Insert: 1.Beginning 2.End 3.Middle 3 Enter the node after which to insert:11 Enter the element:33 1.Insert 2.Delete 3.Display 4.Exit
  • 11. Enter your choice:3 11->33->22 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:2 Delete: 1.Beginning 2.End 3.Middle 3 Enter the node to be deleted: 33 Deleted element :33 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:2 Delete: 1.Beginning 2.End 3.Middle 1 Deletion from the beginning 11 1.Insert 2.Delete 3.Display 4.Exit Enter your choice:2 Delete: 1.Beginning 2.End 3.Middle 2 Deletion from the end 22
  • 12. IMPLEMNTATION OF BINARY SEARCH TREE NON RECURSIVE TRAVERSAL #include<iostream.h> #include<conio.h> #include<stdio.h> #include<malloc.h> #include<process.h> struct bstree { int data; struct bstree*left; struct bstree*right; }*root=NULL; class bst { private: public : void insert(bstree *,int); void inorder_non_rec(bstree*); void preorder_non_rec(bstree*); void postorder_non_rec(bstree*); }; class stack { int top; bstree *stackel[20]; public: stack() { top=-1; } void push(bstree *); bstree* pop(); int empty() { if(top==-1) return(1); else return(0); } };
  • 13. class stack_int { int top; int stack_int[20]; public: stack_int() { top=-1; } void push(int flag); int pop(); int empty_int() { if(top==-1) return(1); else return(0); } }; void stack_int::push(int flag) { stack_int[++top]=flag; } int stack_int::pop() { return(stack_int[top--]); } void stack::push(bstree *node) { stackel[++top]=node; } bstree *stack::pop() { return(stackel[top--]); } void bst :: insert(struct bstree*head,int val) { struct bstree *temp1,*temp2; if(head == NULL) {
  • 14. head=(struct bstree*)malloc(sizeof(struct bstree)); root=head; head->data=val; head->left=NULL; head->right=NULL; } else { temp1=head; while(temp1 != NULL) { temp2=temp1; if(temp1->data > val) temp1=temp1->left; else temp1=temp1->right; } if(temp2->data > val) { temp2->left=(struct bstree*)malloc(sizeof(struct bstree)); temp2=temp2->left; temp2->data=val; temp2->left=NULL; temp2->right=NULL; } else { temp2->right=(struct bstree*)malloc(sizeof(struct bstree)); temp2=temp2->right; temp2->data=val; temp2->left=NULL; temp2->right=NULL; } } } void bst::postorder_non_rec(bstree *root) { stack stk; stack_int stk1; int flag; bstree *temp=root; do { if(temp!=NULL)
  • 15. { stk.push(temp); stk1.push(1); temp=temp->left; } else { if(stk.empty()) break; temp=stk.pop(); flag=stk1.pop(); if(flag==2) { cout<<temp->data; temp=NULL; } else { stk.push(temp); stk1.push(2); temp=temp->right; } } }while(1); } void bst::preorder_non_rec(bstree *root) { stack stk; bstree *temp=root; stk.push(temp); while(!stk.empty()) { temp=stk.pop(); if(temp!=NULL) { cout<<temp->data<<" "; stk.push(temp->right); stk.push(temp->left); } } }
  • 16. void bst::inorder_non_rec(bstree *root) { stack stk; bstree *temp; if(root!=NULL) { temp=root; do { while(temp!=NULL) { stk.push(temp); temp=temp->left; } if(!stk.empty()) { temp=stk.pop(); cout<<temp->data<<" "; temp=temp->right; } else break; }while(1); } else cout<<"Empty tree"; } void main() { int info,opt; char choice; clrscr(); bst b; do { cout<<"n 1-Insert n 2-Inorder n 3-Preordern 4-Postord n 5. Exitn"; cout<<"n ENTER YOUR CHOICE:"; cin>>opt; switch(opt) { case 1: cout<<"n enter the number :"; cin>>info; b.insert(root,info); break;
  • 17. case 2: cout<<"n Inorder n non recursive display is:"; b.inorder_non_rec(root); break; case 3: cout<<"nPreorder n non recursive display is:"; b.preorder_non_rec(root); break; case 4: cout<<"n Post order n non recursive display is:"; b.postorder_non_rec(root); break; case 5: exit(0); } }while(1); } OUTPUT 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 2 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 67 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 12 1.Insert 2.Inorder 3.Preorder
  • 18. 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 45 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 74 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 21 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 2 In order Non recursive display: 2 12 21 45 67 74 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 3 Pre order Non recursive display: 2 67 12 45 21 74 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 4 Post order Non recursive display: 21 45 12 74 67 2
  • 19. IMPLEMENTATION OF BINARY SEARCH TREE RECURSIVE TRAVERSAL #include<iostream.h> #include<conio.h> #include<stdio.h> #include<malloc.h> #include<process.h> struct bstree { int data; struct bstree*left; struct bstree*right; }*root=NULL; class bst { private: public : void insert(bstree *,int); void inorder(bstree*); void postorder(bstree *); void preorder(bstree *); }; class stack { int top; bstree *stackel[20]; public: stack() { top=-1; } void push(bstree *); bstree* pop(); int empty() { if(top==-1) return(1); else return(0); } };
  • 20. class stack_int { int top; int stack_int[20]; public: stack_int() { top=-1; } void push(int flag); int pop(); int empty_int() { if(top==-1) return(1); else return(0); } }; void stack_int::push(int flag) { stack_int[++top]=flag; } int stack_int::pop() { return(stack_int[top--]); } void stack::push(bstree *node) { stackel[++top]=node; } bstree *stack::pop() { return(stackel[top--]); } void bst :: insert(struct bstree*head,int val) { struct bstree *temp1,*temp2; if(head == NULL) {
  • 21. head=(struct bstree*)malloc(sizeof(struct bstree)); root=head; head->data=val; head->left=NULL; head->right=NULL; } else { temp1=head; while(temp1 != NULL) { temp2=temp1; if(temp1->data > val) temp1=temp1->left; else temp1=temp1->right; } if(temp2->data > val) { temp2->left=(struct bstree*)malloc(sizeof(struct bstree)); temp2=temp2->left; temp2->data=val; temp2->left=NULL; temp2->right=NULL; } else { temp2->right=(struct bstree*)malloc(sizeof(struct bstree)); temp2=temp2->right; temp2->data=val; temp2->left=NULL; temp2->right=NULL; } } } void bst :: postorder(struct bstree*head) { if( head != NULL) { postorder(head->left); postorder(head->right); cout<<head->data; } }
  • 22. void bst :: preorder(struct bstree*head) { if( head != NULL) { cout<<head->data; preorder(head->left); preorder(head->right); } } void bst::inorder(bstree *root) { stack stk; bstree *temp; temp=root; if(temp!=NULL) { inorder(temp->left); cout<<temp->data; inorder(temp->right); } } void main() { int info,opt; char choice; clrscr(); bst b; do { cout<<"n 1-Insert n 2-Inorder n 3-Preordern 4-Postorder n 5. Exitn"; cout<<"n ENTER YOUR CHOICE:"; cin>>opt; switch(opt) { case 1: cout<<"n enter the number :"; cin>>info; b.insert(root,info); break; case 2:cout<<"n recursive display is:"; b.inorder(root); break;
  • 23. case 3:cout<<"n recursive display is:"; b.preorder(root); break; case 4:cout<<"n recursive display is:"; b.postorder(root); break; case 5: exit(0); } }while(1); } OUTPUT 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 2 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 67 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 12 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1
  • 24. Enter the element: 45 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 74 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 1 Enter the element: 21 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 2 In order Recursive display: 2 12 21 45 67 74 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 3 Pre order Recursive display: 2 67 12 45 21 74 1.Insert 2.Inorder 3.Preorder 4.Postorder 5.Exit Enter your choice: 4 Post order Recursive display: 21 45 12 74 67 2
  • 25. IMPLEMENTATION OF Breadth First Search #include<iostream.h> #include<conio.h> #include<stdlib.h> int cost[10][10],i,j,k,n,qu[10],front,rare,v,visit[10],visited[10]; main() { int m; cout <<"enter no of vertices"; cin >> n; cout <<"enter no of edges"; cin >> m; cout <<"nEDGES n"; for(k=1;k<=m;k++) { cin >>i>>j; cost[i][j]=1; } cout <<"enter initial vertex"; cin >>v; cout <<"Visitied verticesn"; cout << v; visited[v]=1; k=1; while(k<n) { for(j=1;j<=n;j++) if(cost[v][j]!=0 && visited[j]!=1 && visit[j]!=1) { visit[j]=1; qu[rare++]=j; } v=qu[front++]; cout<<v << " "; k++; visit[v]=0; visited[v]=1; } }
  • 26. OUTPUT: Enter the no of vertices: 9 Enter the no of edges:9 EDGES 1 2 2 3 1 5 1 4 4 7 7 8 8 9 2 6 5 7 Enter initial vertex: 1 Visited vertices 1 2 4 5 3 6 7 8 9
  • 27. IMPLEMENTATION OF Depth First Search #include<iostream.h> #include<conio.h> #include<stdlib.h> int cost[10][10],i,j,k,n,stk[10],top,v,visit[10],visited[10]; main() { int m; cout <<"enterno of vertices"; cin >> n; cout <<"ente no of edges"; cin >> m; cout <<"nEDGES n"; for(k=1;k<=m;k++) { cin >>i>>j; cost[i][j]=1; } cout <<"enter initial vertex"; cin >>v; cout <<" VISITED VERTICES"; cout << v <<" "; visited[v]=1; k=1; while(k<n) { for(j=n;j>=1;j--) if(cost[v][j]!=0 && visited[j]!=1 && visit[j]!=1) { visit[j]=1; stk[top]=j; top++; } v=stk[--top]; cout<<v << " "; k++; visit[v]=0; visited[v]=1; } }
  • 28. OUTPUT: Enter the no of vertices: 9 Enter the no of edges:9 EDGES 1 2 2 3 1 5 1 4 4 7 7 8 8 9 2 6 5 7 Enter initial vertex: 1 Visited vertices 1 2 3 6 4 7 8 9 5
  • 29. IMPLEMENTATION OF HEAP SORT #include<iostream.h> #include<conio.h> #include<stdio.h> void heapify(int a[],int i); void buildheap(int a[]); void heapsort(int a[]); int n; void main() { int a[100]; clrscr(); cout<<"enter n valuen"; cin>>n; int l=n; cout<<"enter array of elementsn"; for(int i=0;i<n;i++) cin>>a[i]; heapsort(a); cout<<"the sorted list of elements are:"<<endl; for(i=0;i<l;i++) cout<<a[i]<<endl; getch(); } void heapify(int a[],int i) { int l,r,large; l=2*i+1; r=2*i+2; if(l<n&&a[l]>=a[i]) large=1; else large=i; if(r<n&&a[r]>=a[large]) large=r; if(i!=large) { int t; t=a[i]; a[i]=a[large]; a[large]=t; heapify(a,large); } }
  • 30. void buildheap(int a[]) { int i; for(i=(n/2)-1;i>=0;i--) heapify(a,i); } void heapsort(int a[]) { buildheap(a); for(int i=n-1;i>=1;i--) { int t; t=a[0]; a[0]=a[i]; a[i]=t; n--; heapify(a,0); } } OUTPUT: enter n value 4 enter array of elements 5 6 3 2 the sorted list of elements are: 2 3 5 6
  • 31. IMPLEMENTATION OF PROGRAM TO CONVERT INFIX TO POSTFIX FORM #include<iostream.h> #include<conio.h> #include<string.h> #define MAXSIZE 100 class STACK_ARRAY { int stack[MAXSIZE]; int Top; public: STACK_ARRAY() { Top=-1; } void push(char); char pop(); int prec(char); void Infix_Postfix(); }; void STACK_ARRAY::push(char item) { if (Top == MAXSIZE-1) { cout<<"nThe Stack Is Full"; getch(); } else stack[++Top]=item; } char STACK_ARRAY::pop() { char item='#'; if (Top == -1) cout<<"nThe Stack Is Empty. Invalid Infix expression"; else item=stack[Top--]; return(item); } int STACK_ARRAY::prec(char symbol) { switch(symbol) { case '(': return(1);
  • 32. case ')': return(2); case '+': case '-': return(3); case '*': case '/': case '%': return(4); case '^': return(5); default: return(0); } } void STACK_ARRAY::Infix_Postfix() { int len,priority; char infix[MAXSIZE],postfix[MAXSIZE],ch; cout<<"nnEnter the infix expression = "; cin>>infix; len=strlen(infix); infix[len++]=')'; push('('); for(int i=0,j=0;i<len;i++) { switch(prec(infix[i])) { case 1: push(infix[i]); break; case 2: ch=pop(); while(ch != '(') { postfix[j++]=ch; ch=pop(); } break; case 3: ch=pop(); while(prec(ch) >= 3) { postfix[j++]=ch; ch=pop();
  • 33. } push(ch); push(infix[i]); break; case 4: ch=pop(); while(prec(ch) >= 4) { postfix[j++]=ch; ch=pop(); } push(ch); push(infix[i]); break; case 5: ch=pop(); while(prec(ch) == 5) { postfix[j++]=ch; ch=pop(); } push(ch); push(infix[i]); break; default: postfix[j++]=infix[i]; break; } } cout<<"nThe Postfix expression is ="; for(i=0;i<j;i++) cout<<postfix[i]; } void main() { char choice; STACK_ARRAY ip; clrscr(); do { clrscr(); ip.Infix_Postfix(); cout<<"nnDo you want to continue (Y/y) ="; cin>>choice;
  • 34. }while(choice == 'Y' || choice == 'y'); } OUTPUT: Enter the infix expression: A+B The postfix expression is AB+ Do you wish to continue(Y/y)= y Enter the infix expression: A+(B-C) The postfix expression is ABC-+ Do you wish to continue(Y/y)=n