Me At MINERVA

Me At MINERVA

THE PHOENIX LEGION

THE PHOENIX LEGION

Facebook Badge

Friday, May 13, 2016

Circular Q

#include
#include
#include
#include
#include
using namespace std;
int a[5],f=-1,r=-1;
int insertion()
{
    int n;
    char s[2];
    do{
        system("CLS");
        cout<<"enter a number /n";
        cin>>n;
     if((f==0 && r<=5) || (r=f-1)){
        cout<<"quene is full /n";
    }
    else{
        if(f==-1){
            f=0;
        }
        if(r>=5){
            r=0;}
            else{
                a[++r]=n;}
    }
    cout<<"for more insertion press y else n /n";
    cin>>s;
    }
    while(s=="y");
}
int deletion()
{
    string s;
    do{
         system("CLS");
    if(f==-1){
        cout<<"quene is emphy /n";}
        else
        {
            a[f]=0;
            if(f==r)
            {
                f=-1;
                r=-1;
            }
            else
{
  if(f==5-1)
 f=0;
  else
 f++;
}
}
             cout<<"For more insertion press y else n /n";
    cin>>s;
    }
    while(s=="y");
    }
int output()
{
         system("CLS");
            if(f==-1){
cout<<"The Circular Queue is Empty";}
 else
 {
if(r < f)
{
for(int i=f;i<=5-1;i++)
  cout< for( int i=0;i<=r;i++)
  cout<
}
else
{
for( int i=f;i<=r;i++)
  cout<
cout< }
 }}

int main()
{
    int x;
    cout<<"for insertion press 1 '\n";
    cout<<"for deletion press 2 \n";
    cout<<"for output press 3 \n";
    cin>>x;
    switch(x){
    case 1:{
      insertion();
      break;}
      case 2:{
          deletion();
          break;}
          case 3:{
              output();
              break;}
              default:{
                  cout<<"you have entered an invalid number /n";
              }
}
return 0;
}

Doubly

#include
#include
#include
using namespace std;
struct student{
int x;
student *next,*tail;
}*current, *start, *temp;
void insert(int n)
{
if (start == NULL)
{
start = new student;
start->x = n;
start->next = NULL;
start->tail = NULL;
}
else{
current = start;
while (current->next != NULL)
{
current = current->next;
}
temp = new student;
temp->x = n;
temp->next = NULL;
current->next = temp;
temp->tail = current;

}
}
void print()
{

if (start == NULL)
{
cout << "ERROR: LINK LIST IS EMPTY \n";
}
else{
current = start;
while (current->next != NULL)
{
cout << current->x << endl;
current = current->next;
}
cout << current->x << endl;

}
}
void search(int n)
{
int flag = 2;
if (start == NULL)
{
cout << "Error:LINK LIST IS EMPTY \n";
}
else
{
current = start;
while (current->next != NULL)
{
if (current->x == n)
{
cout << " FOUND \n";
flag = 1;
current = current->next;
}
else{
current = current->next;
}
}
if (flag != 1)
{
cout << "ERROR: NOT FOUND \n";
}
}
}
int count()
{
int x = 1;
if (start == NULL)
{
cout << " ERROR:LINK LIST IS EMPTY \n";
}
else
{
current = start;
while (current->next != NULL)
{
x++;
current = current->next;
}
cout << "count =   " << x << endl;
return x;
}

}
void insertfirst(int n)
{
if (start == NULL)
{
start = new student;
start->x = n;
start->next = NULL;
start->tail = NULL;
}
else
{
current = start;
start = new student;
start->x = n;
start->next = current;
start->tail = NULL;
current->tail = start;
}
}
void insertionmiddle(int n)
{
int p;
if (start == NULL)
{
cout << "There is no node in the libarary so there is no insertion of your choice hence the node you enter is the the first node \n";
cout<< "P.S You can ignore the big statement"< start = new student;
start->x = n;
start->next =start->tail= NULL;
}
else{
cout << "Enter a position on which point you want to insert a value \n";
cin >> p;
if (count() > p){
cout << "you have enter an invalid position \n";
}
else{
current = start;
for (int i = 1; i < p ; i++){
current = current->next;
}
temp = new student;
temp->x = n;
temp->next = current->next;
temp->tail = current;
current->next = temp;
}
}
}
void delse( int del,int c)
{
current = start;
for (int i = 1; i <= c; i++)
{
if (current->x == del)
{
temp->next = current->next;
current->tail = temp;
delete current;
}
temp = current;
current=current->next;
}

}
void delfi()
{
current = start;
start = start->next;
start->tail = NULL;
delete current;
}
void delen()
{
current = start;
while (current->next = NULL){
temp = current;
current = current->next;
}
temp->next = NULL;
delete current;

}
void delpo(int n){
current = start;
for(int i = 1; i < n; i++){
temp = current;
current = current->next;
}
temp->next = current->next;
temp->tail = current;
delete current;
}

int main()
{
   system("COLOR F0");
string s;
int x;
do{
system("CLS");
cout << "for insertion press 1 \n";
cout << "for deletion press 2 \n";
cout << "for searching press 3 \n";
cout << "for counting total number of node press 4 \n";
cout << "for printing press 5 \n";
cin >> x;
switch (x)
{
case 1:{
int x, n, p;
string s;
do{
system("CLS");
cout << "For insertion at start press 1 \n";
cout << "For insertion at the end press 2\n";
cout << "For insertion at your choice point press 3\n";
cin >> x;
switch (x){
case 1:
{
cout << "enter a number \n";
insertfirst(n);
break;
}
case 2:
{cout << "enter a number \n";
cin >> n;
insert(n);
break; }
case 3:{
cout << "enter a number \n";
cin >> n;
insertionmiddle(n);
break;
}
default:
{
cout << "Hey, you have press an invalid key -_- \n";
}
}
cout << "For more insertion press y else n Okay? \n";
cin >> s;
} while (s == "y");
break;}
case 2:
{
int x, n, p;
string s;
do{
system("CLS");
cout << "deletion at start press 1 \n";
cout << "deletion at the end press 2\n";
cout << "deletion at your choice point press 3\n";
cin >> x;
switch (x){
case 1:{
delfi();
break;
}
case 2:{
delen();
break;
}
case 3:{
cout << "Kindly enter the position on which point you want to delete a value \n";
cin >> p;
delpo(p);
break;
}
default:
{
cout << "Oh please! you have press invalid key \n";
}}
cout << "For more deletion press y else n \n";
cin >> s;}
while (s == "y");
break;}
case 3:
{
int n;
cout << "ENTER A NUMBER FOR SEARCHING \n";
cin >> n;
search(n);
break;}
case 4:{
           cout<<"total number of nodes are   "< break;}
case 5:
{
print();
break;
}
default:{
cout << "What the hell! you have entered an invalid key \n";
}
}
system("CLS");
cout << "For more operation press y else n \n";
cin >> s;}
while (s == "y");
system("pause");
    return 0;
}

Infix to Postfix

#include
#include
#include
#include
#include
#include
using namespace std;
int check(char a);

int main()
{
    char s[100];
stackin;
char out[100];
    int i=0,y,z=0,flag=1;
    char ch;
    system("COLOR F0");
cout << "ENTER A INFIX NOTATION "< cin>>s;
int x=strlen(s);
while (i    ch=s[i];
   if((ch=='(')||(ch==')'))
   {
           if (ch == '(')
   {
       in.push(ch);
}
else
{
   while((in.top()!='(')&&(!in.empty()))
   {
                out[z++]=in.top();
       in.pop();
   }
       if(!in.empty())
       {
           in.pop();
       }
}
   }
   else{
int temp=check(ch);
if(temp==0){
   out[z++]=ch;
}
else{
   if(in.empty()&&(temp>=1))
   {
       in.push(ch);
   }
            else
            {
            while(temp<=(check(in.top()))&&(!in.empty())&&(in.top()!='('))
            {
     out[z++]=in.top();
     in.pop();
}
in.push(ch);
}
}
   }
i++;
}
while (!in.empty()) {
      out[z++] = in.top();
      in.pop();
   }
 out[z]=0;
 cout<return 0;
}
int check(char a)
{
    switch(a)
    {
        case '+':
        return 1;
        case '-':
        return 1;
        case '*':
        return 2;
        case '/':
        return 2;
        case '^':
        return 3;
        default:
        return 0;
    }
}


Stack

#include
#include
#include
using namespace std;
int *a=new int [5],top=-1;
void push()
{
    int n,flag;
    string s;
    do{
        system("CLS");
        if((top>=-1)&&(top<5 p="">     cout<<"ENTER A DIGIT \n";
                cin>>n;
        a[++top]=n;
    }
    else
    {
        cout<<"STACK IS FULL \n";
         flag=1;
         break;
    }
    if(flag!=1){
     cout<<"DO YOU WANT TO DO MORE OPERATION PRESS Y ELSE N \n";
      cin>>s;
    }
    else{
        cout<<"ALL SPACES ARE FULL \n";
        break;
    }
    }
    while(s=="y");

}
void pop()
{
    system("CLS");
    if(top==0)
    {
        cout<<"STACK IS EMPTHY \n";
    }
    else{
        system("CLS");
        cout<<"THE FOLLOWING NUMBER OF STACK IS"<<"  "<        top--;
    }

}
void output()
{
    system("CLS");
    if(top==0)
    {
        cout<<"STACK IS EMPTHY \n";
    }
    else
    {
        cout<<"[";
        while(top>=0)
        {
            if(top>=0)
            cout<<" "<
        }
        cout<<"]"<    }
}
int main()
{
    int x;
    string s;
    do{
    system("COLOR F0");
    system("CLS");
    cout<<"FOR PUSH PRESS 1\n";
    cout<<"FOR POP PRESS 2 \n";
    cout<<"FOR VIEW ALL THE DIGIT PRESS 3 \n";
    cout<<" FOR EXIT PRESS 4\n";
    cin>>x;
    switch(x)
    {
        case 1:{
            system("CLS");
            push();
            break;
        }
                case 2:{
                    string s;
                    system("CLS");
                    do {
                    pop();
                    cout<<"DO YOU WANT TO DO MORE DELETION PRESS Y ELSE N \n";
                    cin>>s;
                    }
                    while(s=="y");
                break;}
                case 3:{
                    system("CLS");
                    output();
                break;}
                case 4:{
                    system("CLS");
                    goto i;
                break;}
                }
                cout<<"DO YOU WANT TO DO MORE OPERATION PRESS Y ELSE N \n";
                 cin>>s;
    }
    while(s=="y");
                i:
                {
                    cout<<"PROGRAM IS CLOSE \n";}
    return 0;
}

QUEUE

#include
#include
#include
using namespace std;
int a[5], f = -1, r = -1;
void insertion(void)
{
int n;
char s;
do{
cout << "enter a number \n";
cin >> n;
system("CLS");
if (r >= 5){
cout << "quene is full \n";
}
else{
a[++r] = n;
if (f == -1){
f = 0;
}
}
cout << "If you want to do more operation press y else n \n";

cin >> s;
} while (s == 'y');
}
void deletion(void)
{
char s;
do{
system("CLS");
if (f == -1){
cout << "quene is empty \n";
}
else{
a[f] = 0;
if (f == r){
f = r = -1;
}
else{
f++;
}
}
cout << "If you want to do more operation press y else n \n";
cin >> s;
} while (s == 'y');
}
void output()
{
if (f == 0)
{
for (int i = f; i <= r; i++)
{
cout << a[i] << endl;
}
}
else
{
cout << "quene is empty \n";
}
}
int main()
{
char s;
int x;
system("COLOR F0");
do{
system("CLS");
cout << "for insertion press 1 \n";
cout << "for deletion press 2 \n";
cout << "for output press 3 \n";
cin >> x;
switch (x){
case 1:{
insertion();
break; }
case 2:{
deletion();
break; }
case 3:{
output();
break; }
default:{
cout << "entry is an invalid number /n";
}
}
cout << "If you want to do more operation press y else n \n";
cin >> s;
} while (s == 'y');

return 0;
}

Binary Tree

#include
#include
using namespace std;
struct tree
{
int n;
tree *left, *right;
}*root, *current, *temp,;
void insertion(int n)
{
if (root == NULL)
{
root = new tree;
root->n = n;
root->left = root->right = NULL;
}
else{
current = root;
while (current != NULL)
{
if (n >= current->n)
{
temp = current;
current = current->right;
}
else
{
temp = current;
current = current->left;
}
}
if (n >= temp->n)
{
current = new tree;
current->n = n;
current->left =current->right= NULL;
temp->right=current;
}
else{
current = new tree;
current->n = n;
current->right = current->left=NULL;
temp->left=current;
}

}
}
void search(int n)
{
if (root == NULL)
{
cout << "empty \n";
}
else{
current = root;
while (current != NULL)
{

if (current->n == n)
{
break;
}
if (n > current->n)
{
current = current->right;
}
if (n < current->n)
{
current = current->left;
}
}
if (current == NULL)
{
cout << "OOPS! NOT FOUND \n";
}
else
{
if (current->n == n)
{
cout << "Yaaayyy! Found \n";
}
}
}
current=NULL;

}
void remove(int n)
{
if (root == NULL)
{
cout << "empty \n";
}
else{
current = root;
while (current != NULL)
{

if (current->n == n)
{
break;
}
if (n > current->n)
{
current = current->right;
}
if (n < current->n)
{
current = current->left;
}
}
if (current == NULL)
{
cout << "OOPS! NOT FOUND\n";
}
else
{
if ((current->left == NULL) && (current->right == NULL))
{
delete current;
current = NULL;
}
if (current->left = NULL)
{
temp = current;
current = current->right;
delete temp;

}
if (current->right = NULL)
{
temp = current;
current = current->left;
delete temp;
}
else{
   temp=current;
    while(current->left != NULL){
     current= current->left;}
       current->n = temp->n;
                  remove(current->n);
}
}}
}
int preorder(tree *head)
{
    if(head==NULL){
        return 0;}
    cout << head->n<<"  ";
preorder(head->left);
preorder(head->right);
}
int inorder(tree *head)
{
    if(head==NULL){
        return 0;}
preorder(head->left);
cout << head->n<<"  ";
preorder(head->right);}
int postorder(tree *head)
{
    if(head==NULL){
        return 0;}
preorder(head->left);
preorder(head->right);
cout << head->n<<"  ";}


int main()
{
   int x, y, o, z;
do
{
system("CLS");
system("COLOR F0");
cout << "1..INSERTION \n";
cout << "2.. DELETION \n";
cout << "3.. SEARCH \n";
cout << "4..DISPLAY \n";
cin >> x;
switch (x)
{
case 1:{
cout << "ENTER NUMBER \n";
cin >> y;
insertion(y);
break;
}
case 2:
{
cout << "ENTER A NUMBER \n";
cin >> z;
remove(z);
break; }
case 3:{
cout << "ENTER A NUMBER /n";
cin >> z;
search(z);
break;
}
case 4:{
if (root == NULL){
cout << "THE TREE IS EMPTY \n";}
else
{
   cout< inorder(root);
cout<
postorder(root);
cout< preorder(root);
}
break;
}
}
cout << "PRESS 1..FOR MORE OPERATIONS \n";
cin >> o;
} while (o == 1);
    return 0;
}

Simple Link List

#include
using namespace std;

void main_menu();
void insertion (int n);
void del (int x);
void search();

struct Node  // node is naame it could me anything
{
int data;
Node * next;
};





Node *start,*current,*temp='\0';
int Tayyaba=0;

int main ()
{
main_menu();

return 0;
}


void main_menu()
{
int w=1;

while(w==1)
{

char choice;

cout<<"--   IMPLIMENTATION OF Linked list --"< cout<<"\t\t\t==========>> 1: Insertion         "< cout<<"\t\t\t==========>> 2: Delete          "< cout<<"\t\t\t==========>> 3: View         "< cout<<"\t\t\t==========>> 4: Search       "< cout<<"\t\t\t==========>> 5: Exit         "<
cout<<"\n\n\t\t\t Select option wisely"< cin>>choice;

switch(choice)
{
case '1':

system("cls");
int n;
cout<<"enter value you want to insert"< cin>>n;
insertion(n);
break;

case '2':
system("cls");


break;
case '3':
system("cls");
//print();
break;

case '4':

system("cls");

break;

case '5':
system("cls");
w++;
break;
default :
system("cls");

}

}
}


void insertion (int n)
{
if(start=='\0')
{
start =new Node;
start->data=n;
start->next='\0';
}
else
{
current=start;
while (current->next!='\0')
{
current=current->next;
temp=new Node;
temp->data =10;
temp->next='\0';
current=current->next;

}
}
}


void del ()
{
int val=0,n=0;


//deletion from start//

if (start == NULL)
cout << "There is no linked list node to pop.\n";
else{
temp = start;
cout << "enter the value you want to delete :";
cin >> n;

while (temp->next != NULL){
if (temp->data == n){
cout << "temp data =" << temp->data << " n =" << n << endl;
current = start;
break;
}
else
temp = temp->next;
}

while (current->next != NULL){
if (current->next == temp){
cout << "current next=" << current->next << " temp =" << temp << endl;

current->next = temp->next;
temp->next = NULL;
delete temp;
}
else
current = current->next;
}

}

// deletion from star with only one node //

if (start->next == NULL && start->data == n){
start = NULL;
}


//deletion from start//
if (start->data == n){
temp = start;
start = start->next;
temp->next = NULL;
delete temp;
}


// deletion from end//
temp = start;
while (temp->next != NULL)
temp = temp->next;

if (temp->data==n)
{
cout << "temp data =" << temp->data << " n =" << n<< endl;
current = start;
while (current->next != NULL){
if (current->next == temp){
current->next = NULL;
cout << "this value will del =" << temp->data << endl;
delete temp;
}
else
current = current->next;
}
}

}


void search()
{
int x;
cout<<"enter value you want to search "< cin>>x;
while(current->next !='\0')

if(x==current->data)
{
cout<<"Search is found"<data;

}
else
{
cout<<"result not found"< }
}