Posts

Showing posts from November 17, 2019

Infix to Postfix

Image
Program #include<iostream> #include<conio.h> #include<stdio.h> using namespace std; #define MAX 100 class stack{  int top;  char infix[MAX],postfix[MAX],s[MAX];  public:   stack()   {   top=-1; }   void read();   char Push(char);   char Pop();   int conversion();   char Prioity(char);   void display(); }; char stack::Push(char a){  if(top>MAX)  cout<"STACK is over flow";  else{   top++;   s[top]=a;  } } char stack::Pop(){  char item;  if(top==-1)     {        cout<<"\n Stack is under flow"<<endl;     }     else     { item=s[top];      top--;      return item; } } char stack::Prioity(char x){  switch(x){      case'(':   return 0;   case'+':   return 1;   case'-':  ...

JOSEPHUS PROBLEM

Image
JOSEPHUS PROBLEM CODE #include <iostream> using namespace std; int counter=0,i,k=0; struct Node{ int data; Node *next; }; class circular { public: int d; Node *rear,*prev,*next,*first; circular() { rear=NULL; } void insertNode(int d) { Node *New=new Node; //cin>>d; if (rear==NULL) { New->data=d; New->next=New; first=New; prev=New; first=New; rear=New; } else { New->data=d; New->next=first; prev->next=New; prev=New;     rear=New; } } void display() { Node *current=first; while(current !=rear)              { cout<<current->data<<" "; current=current->next; } if(current==rear)               {       ...