If Any Required Program Please Ask In Comment I Will Help You(any Program in JAVA or C++) . . THANKS FOR VISITING MY BLOG!

If U LIKE MY PROFILE RAISE YOUR HAND IF U NOT RAISE UR STANDARD. Powered by Blogger.

Friday, October 26, 2018

PROGRAM TO FIND NUMBER AND IT'S OCCURRENCES USING LINK LIST.



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

using namespace std;

class Chain;

template <class Type>

class Node
{
private:
Type Info;
Node<int> *Link;
friend class Chain;
};

class Chain
{
private:
Node<int> *First;

public:
Chain()
{
First = NULL;
}

void Head_Insert(int Value)
{
Node<int> *Temp = new Node<int>;

Temp->Info = Value;
Temp->Link = First;

First = Temp;
}

void Print()
{
if (ListMsg())
{
cout << "\nLIST OVERFLOWED...!!!\n";
exit(1);
}

for (Node<int> *Temp = First; Temp != NULL; Temp = Temp = Temp->Link)
cout << "Value of Node is: " << Temp->Info << endl;
}

void Search_Occur(int Value)
{
int Count;

for (Node<int> *Temp = First; Temp != NULL; Temp = Temp->Link)
{
if (Temp->Info == Value)
Count++;
}

cout << "\nValue found " << Count << " times in LIST." << endl;
}

inline bool ListMsg()
{
return First == NULL;
}
};

int main()
{
Chain Obj;

for (int I = 0; I < 10; I++)
{
Obj.Head_Insert(I);
}

Obj.Print();

Obj.Search_Occur(1);

getch();
return 0;
}

PROGRAM FOR SEARCHING IN LINK LIST.



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

using namespace std;

class Chain;

template <class Type>

class Node
{
private:
Type Info;
Node<int> *Link;
friend class Chain;
};

class Chain
{
private:
Node<int> *First;

public:
Chain()
{
First = NULL;
}

void Head_Insert(int No)
{
Node<int> *Temp = new Node<int>;

Temp->Info = No;
Temp->Link = First;

First = Temp;
}

void Print()
{
if (ListMsg())
{
cout << "\nLIST OVERFLOWED...!!!\n";
exit(1);
}

for (Node<int> *Temp = First; Temp != NULL; Temp = Temp->Link)
cout << "Value of Node is: " << Temp->Info << endl;
}

Node<int>* Search(int Value)
{
bool Find = false;

Node<int> *Temp;
for (Temp = First; Temp != NULL && !Find; Temp = Temp->Link)
{
if (Temp->Info == Value)
Find = true;
}

return Temp;
}

inline bool ListMsg()
{
return First == NULL;
}
};

int main()
{
Chain Obj;

Obj.Head_Insert(1);
Obj.Head_Insert(2);
Obj.Head_Insert(3);
Obj.Head_Insert(4);
Obj.Head_Insert(5);

Node<int> *Obj1 = Obj.Search(2);

if (Obj1 == NULL)
cout << "\nValue Not Found In LIST....!!!!\n" << endl;

else
cout << "\nValue Found...!!! \n" << endl;

getch();
return 0;
}

LINKED LISTS TO PRINT ELEMENTS IN REVERSE ORDER USING RECURSION.



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

using namespace std;

class Chain;

template <class Type>

class Node
{
private:
Type Info;
Node<int> *Link;
friend class Chain;
};

class Chain
{
private:
Node<int> *First;

public:
Chain()
{
First = NULL;
}

void Head_Insert(int Value)
{
Node<int> *Temp = new Node<int>;

Temp->Info = Value;
Temp->Link = First;
First = Temp;
}

void Print()
{
if (ListMsg())
{
cout << "\nLIST UNDERFLOWED...!!!!\n";
exit(1);
}

for (Node<int> *Temp = First; Temp != NULL; Temp = Temp->Link)
cout << "Value of Node is: " << Temp->Info << endl;
}

void Recursion(Node<int> *Ptr)
{
if (Ptr == NULL)
return;

cout << "Value is: " << Ptr->Info << endl;
Recursion(Ptr->Link);
}

void Reverse_Order()
{
Recursion(First);
}

inline bool ListMsg()
{
return First == NULL;
}
};

int main()
{
Chain Obj;

Obj.Head_Insert(1);
Obj.Head_Insert(2);
Obj.Head_Insert(3);
Obj.Head_Insert(4);
Obj.Head_Insert(5);

Obj.Print();

getch();
return 0;
}

PROGRAM FOR THE LINKED LISTS TO COUNT EVEN NODES.



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

using namespace std;

class Chain;

template <class Type>

class Node
{
private:
Type Info;
Node<int> *Link;
friend class Chain;
};

class Chain
{
private:
Node<int> *First;

public:
Chain()
{
First = NULL;
}

void Head_Insert(int Value)
{
Node<int> *Temp = new Node<int>;

Temp->Info = Value;
Temp->Link = First;
First = Temp;
}


void Print()
{
int Count = 0;

if (ListMsg())
{
cout << "\nLIST UNDERFLOWED...!!!!\n";
exit(1);
}

for (Node<int> *Temp = First; Temp != NULL; Temp = Temp->Link)
{
if (Temp->Info % 2 == 0)
Count++;

cout << "Value of Node is: " << Temp->Info << endl;
}

cout << "\nThere are " << Count << " Even Nodes in List.\n" << endl;
}

inline bool ListMsg()
{
return First == NULL;
}
};

int main()
{
Chain Obj;

Obj.Head_Insert(1);
Obj.Head_Insert(2);
Obj.Head_Insert(3);
Obj.Head_Insert(4);
Obj.Head_Insert(5);

Obj.Print();

getch();
return 0;
}

PROGRAM FOR THE LINKED LISTS TO COUNT NODES.



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

using namespace std;

class Chain;

template <class Type>

class Node
{
private:
Type Info;
Node<int> *Link;
friend class Chain;
};

class Chain
{
private:
Node<int> *First;

public:
Chain()
{
First = NULL;
}

void Head_Insert(int Value)
{
Node<int> *Temp = new Node<int>;

Temp->Info = Value;
Temp->Link = First;
First = Temp;
}

void Print()
{
int Count = 0;

if (ListMsg())
{
cout << "\nLIST UNDERFLOWED...!!!!\n";
exit(1);
}

for (Node<int> *Temp = First; Temp != NULL; Temp = Temp->Link)
{
cout << "Value of Node is: " << Temp->Info << endl;
Count++;
}

cout << "\nThere are " << Count << " Nodes in List.\n" << endl;
}

inline bool ListMsg()
{
return First == NULL;
}
};

int main()
{
Chain Obj;

Obj.Head_Insert(1);
Obj.Head_Insert(2);
Obj.Head_Insert(3);
Obj.Head_Insert(4);
Obj.Head_Insert(5);

Obj.Print();

getch();
return 0;
}

PROGRAM FOR THE LINKED LISTS.



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

using namespace std;

class Chain;

template <class Type>

class Node
{
private:
Type Info;
Node<int> *Link;
friend class Chain;
};

class Chain
{
private:
Node<int> *First;

public:
Chain()
{
First = NULL;
}

void Head_Insert(int Value)
{
Node<int> *Temp = new Node<int>;

Temp->Info = Value;
Temp->Link = First;
First = Temp;
}

void Print()
{
if (ListMsg())
{
cout << "\nLIST UNDERFLOWED...!!!!\n";
exit(1);
}

for (Node<int> *Temp = First; Temp != NULL; Temp = Temp->Link)
cout << "Value of Node is: " << Temp->Info << endl;
}

void Head_Del()
{
Node<int> *Temp = First;

if (ListMsg())
{
cout << "\nLIST OVERFLOWED...!!!\n" << endl;
exit(1);
}

First = Temp->Link;
cout << "Delete Node of value: " << Temp->Info << endl;
delete(Temp);
}

inline bool ListMsg()
{
return First == NULL;
}
};

int main()
{
Chain Obj;

Obj.Head_Insert(1);
Obj.Head_Insert(2);
Obj.Head_Insert(3);
Obj.Head_Insert(4);
Obj.Head_Insert(5);

Obj.Print();

Obj.Head_Del();
Obj.Head_Del();
Obj.Head_Del();
Obj.Head_Del();
Obj.Head_Del();

getch();
return 0;
}

Sunday, October 21, 2018

CHECK WHETHER STRING IS PALINDROME USING STACK.



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

using namespace std;

template <class Type>

class Palindrom
{
private:
int Top, Size;
Type *Arr;

public:
Palindrom(int Siz)
{
Top = -1;
Size = Siz;
Arr  = new Type[Size];

strcpy(Arr, "\0");
}

void Push(Type Ch)
{

if(Top == Size-1)
{
cout << "\nStack Overflowed..........." << endl;
exit(1);
}

Arr[++Top] = Ch;
}

Type Pop()
{
if(isEmpty())
{
cout << "\nStack Underflowed............" << endl;
exit(1);
}

return Arr[Top--];
}

inline bool isEmpty()
{
return (Top == -1);
}

void Read_Check(char *Arrays)
{
    for(int I =0; I <strlen(Arrays); I++)
        {
            char Ch = Arrays[I];
            Push(Ch);
        }

        for(int I =0; I <strlen(Arrays); I++)
           Arrays[I]  = Pop();

        if(strcmp(Arr, Arrays) == 0)
            cout << "\nString is Palindrome.\n" << endl;

        else
            cout << "\nIt is Not Palindrome.\n" << endl;
}

~Palindrom()
{
cout << "\n\n\n----------PROGRAM ENDED---------------\n\n\n" << endl;
}
};

int main()
{
    char Array[100];
Palindrom<char> Obj1(5);

cout << "Enter Your String: ";
cin >> Array;

Obj1.Read_Check(Array);

getch();
return 0;
}

CHECK BRACKETS OF EXPRESSION ARE BALANCED or NOT using STACK.



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

using namespace std;

template <class Type>

class Brackets
{
private:
Type *Stack, *String;
bool Valid;
int Size, Top;

public:
Brackets(int Siz)
{
Size = Siz;

Stack = new Type[Size];
strcpy(Stack, "\0");

Valid = true;
Top = -1;
}

void Push(Type Ch)
{
if (Top == Size - 1)
{
cout << "\nString Overflowed......." << endl;
exit(1);
}

else
Stack[++Top] = Ch;
}

Type Pop()
{
if (IsEmpty())
{
cout << "\nStack Underflowed........" << endl;
exit(1);
}

else
return Stack[Top--];
}

void chkBrkt(Type Chr)
{
char Ch1, Ch2;

Ch1 = Chr;
if (Ch1 == '(' || Ch1 == '{' || Ch1 == '[')
Push(Ch1);

if (Ch1 == ')' || Ch1 == '}' || Ch1 == ']')
{
if (IsEmpty())
Valid = false;

else
{
Ch2 = Pop();

if (!((Ch2 == '(' && Ch1 == ')') || (Ch2 == '{' && Ch1 == '}') || (Ch2 == '[' && Ch1 == ']')))
Valid = false;
}
}
}

void Check()
{
if (!IsEmpty())
Valid = false;

if (Valid == true)
cout << "\nExpression's Brackets are Balanced and Expression Is Valid......\n" << endl;

else
cout << "\nExpression's Brackets are Unbalanced and Expression Is Invalid......\n" << endl;
}

inline bool IsEmpty()
{
return (Top == -1);
}

~Brackets()
{
cout << "\n\n\n\n******************PROGRAM ENDED******************\n\n\n\n" << endl;
}
};

int main()
{
Brackets<char> Obj(100);
char *Ch = new char[100];

cout << "Enter Expression: ";
cin >> Ch;

for (int I = 0; Ch[I] != '\0'; I++)
{
Obj.chkBrkt(Ch[I]);
}

Obj.Check();

getch();
return 0;
}

PROGRAM TO STORE char IN STACK USING TEMPLATES.



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

using namespace std;

template <class Type>

class Stack
{
private:
Type *Arr;
int Top, Size;

public:
Stack(int Siz)
{
Size = Siz;

Arr = new Type[Size];
for (int I = 0; I <Size; I++)
{
Arr[I] = 0;
}

Top = -1;
}

void Push(Type Num)
{
if (Top == Size - 1)
{
cout << "\nStack Overflowed..........." << endl;
exit(1);
}

Arr[++Top] = Num;
}

Type Pop()
{
if (IsEmpty())
{
cout << "\nStack Underflowed..........." << endl;
return 0;
}

return Arr[Top--];
}

inline bool IsEmpty()
{
return (Top == -1);
}

~Stack()
{
cout << "\n\n\n\n\n\n\n..........Program Ended...........\n\n\n\n\n\n\n\n\n";
}
};

int main()
{
Stack<char> Obj1(5);

Obj1.Push('M');
Obj1.Push('A');
Obj1.Push('D');
Obj1.Push('A');
Obj1.Push('M');

cout << "String is: " << endl;

while (!Obj1.IsEmpty())
cout << Obj1.Pop();

getch();
return 0;
}

PROGRAM TO SIMPLIFY PREFIX EXPRESSION.



#include <iostream>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <cctype>
#include <stdlib.h>

using namespace std;

template <class Type>

class Simplify
{
private:
Type *Stack;
int Top, Size;

public:
Simplify(int Siz)
{
Size = Siz;

Stack = new Type[Size];

for(int I =0; I <Size; I++)
{
    Stack[I] = 0;
}

Top = -1;
}

void Push(Type Ch)
{

if(IsFull())
{
cout << "\n\n\nSTACK OVERFLOWED!!!!!!\n\n\n" << endl;
exit(1);
}

Stack[++Top] = Ch;
}

Type Pop()
{
if(IsEmpty())
{
cout << "\n\n\nSTACK UNDERFLOWED!!!!!!!!!\n\n\n" << endl;
exit(1);
}

return Stack[Top--];
}

Type Result(string Ptr)
{
    Simplify<char> Obj(100);
        int Oprnd1, Oprnd2, Rezult, Count = 0;
char Symb;

for(int I = 0; I <Ptr.length(); I++)
        {
            Symb = Ptr[I];

            if( isdigit(Symb) )
                Obj.Push(Symb - '0');

            else
            {
                Push(Symb);
                Count++;
            }
        }

for(int I = 0; I < Count; I++)
{
    Symb = Stack[I];

Oprnd2 = Obj.Pop();
Oprnd1 = Obj.Pop();

if(Symb ==  '+')
Rezult = Oprnd1 + Oprnd2;

else if(Symb == '-')
Rezult = Oprnd1 - Oprnd2;

else if(Symb == '*')
Rezult = Oprnd1 * Oprnd2;

else if(Symb == '/')
Rezult = Oprnd1 / Oprnd2;

else if(Symb == '^')
Rezult = pow(Oprnd1, Oprnd2);

else
exit(1);

Obj.Push(Rezult);
}

return Obj.Pop();
}

inline bool IsFull()
{
return (Top == Size -1);
}

inline bool IsEmpty()
{
return (Top == -1);
}

~Simplify()
{
cout << "\n\n\n***********PROGRAM ENDED************\n\n\n" << endl;
}
};

int main()
{
    Simplify<int> Obj(100);
string Statement;

cout << "Enter Any Expression: ";
cin >> Statement;

cout << "\nResults Of PREFIX Expression is: " << Obj.Result(Statement) << endl;

getch();
return 0;
}

PROGRAM TO SIMPLIFY POSTFIX EXPRESSION.



#include <iostream>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <cctype>
#include <stdlib.h>

using namespace std;

template <class Type>

class Simplify
{
private:
Type *Stack;
int Top, Size;

public:
Simplify(int Siz)
{
Size = Siz;

Stack = new Type[Size];

for(int I =0; I <Size; I++)
{
    Stack[I] = 0;
}

Top = -1;
}

void Push(Type Ch)
{

if(IsFull())
{
cout << "\n\n\nSTACK OVERFLOWED!!!!!!\n\n\n" << endl;
exit(1);
}

Stack[++Top] = Ch;
}

Type Pop()
{
if(IsEmpty())
{
cout << "\n\n\nSTACK UNDERFLOWED!!!!!!!!!\n\n\n" << endl;
exit(1);
}

return Stack[Top--];
}

Type Result(string Ptr)
{
        int Oprnd1, Oprnd2, Rezult;
char Symb;

for(int I =0; I < Ptr.length(); I++)
{
Symb = Ptr[I];

if( isdigit(Symb) )
Push(Symb - '0');

else
{
Oprnd2 = Pop();
Oprnd1 = Pop();


if(Symb ==  '+')
Rezult = Oprnd1 + Oprnd2;

else if(Symb == '-')
Rezult = Oprnd1 - Oprnd2;

else if(Symb == '*')
Rezult = Oprnd1 * Oprnd2;

else if(Symb == '/')
Rezult = Oprnd1 / Oprnd2;

else if(Symb == '^')
Rezult = pow(Oprnd1, Oprnd2);

else
exit(1);

Push(Rezult);
}
}

return Pop();
}

inline bool IsFull()
{
return (Top == Size -1);
}

inline bool IsEmpty()
{
return (Top == -1);
}

~Simplify()
{
cout << "\n\n\n***********PROGRAM ENDED************\n\n\n" << endl;
}
};

int main()
{
    Simplify<int> Obj(100);
string Statement;

cout << "Enter Any Expression: ";
cin >> Statement;

cout << "\nResults Of Postfix Expression is: " << Obj.Result(Statement) << endl;

getch();
return 0;
}

PROGRAM TO SIMPLIFY INFIX EXPRESSION.



#include <iostream>
#include <conio.h>
#include <string.h>
#include <math.h>
#include <cctype>
#include <stdlib.h>

using namespace std;

template <class Type>

class Simplify
{
private:
Type *Stack;
int Top, Size;

public:
Simplify(int Siz)
{
Size = Siz;

Stack = new Type[Size];

for(int I =0; I <Size; I++)
{
    Stack[I] = 0;
}

Top = -1;
}

void Push(Type Ch)
{

if(IsFull())
{
cout << "\n\n\nSTACK OVERFLOWED!!!!!!\n\n\n" << endl;
exit(1);
}

Stack[++Top] = Ch;
}

Type Pop()
{
if(IsEmpty())
{
cout << "\n\n\nSTACK UNDERFLOWED!!!!!!!!!\n\n\n" << endl;
exit(1);
}

return Stack[Top--];
}

Type Result(string Ptr)
{
    Simplify<char> Obj(100);
        int Oprnd1, Oprnd2, Rezult, Count = 0;
char Symb;

for(int I = 0; I <Ptr.length(); I++)
        {
            Symb = Ptr[I];

            if( isdigit(Symb) )
                Obj.Push(Symb - '0');

            else
            {
                Push(Symb);
                Count++;
            }
        }

for(int I =0; I < Count; I++)
{
    Symb = Pop();

Oprnd2 = Obj.Pop();
Oprnd1 = Obj.Pop();


if(Symb ==  '+')
Rezult = Oprnd1 + Oprnd2;

else if(Symb == '-')
Rezult = Oprnd1 - Oprnd2;

else if(Symb == '*')
Rezult = Oprnd1 * Oprnd2;

else if(Symb == '/')
Rezult = Oprnd1 / Oprnd2;

else if(Symb == '^')
Rezult = pow(Oprnd1, Oprnd2);

else
exit(1);

Obj.Push(Rezult);
}

return Obj.Pop();
}

inline bool IsFull()
{
return (Top == Size -1);
}

inline bool IsEmpty()
{
return (Top == -1);
}

~Simplify()
{
cout << "\n\n\n***********PROGRAM ENDED************\n\n\n" << endl;
}
};

int main()
{
    Simplify<int> Obj(100);
string Statement;

cout << "Enter Any Expression: ";
cin >> Statement;

cout << "\nResults Of INFIX Expression is: " << Obj.Result(Statement) << endl;

getch();
return 0;
}

PROGRAM FOR Tower Of Hanoi.



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

using namespace std;

int TOH(int, char, char, char );

int main()
{
int No;

cout << "Enter Number Of Disks: ";
cin >> No;

TOH(No, 'A', 'B', 'C');

    getch();
return 0;

}

int TOH(int N, char Src, char Aux, char Dest)
{
if (N == 1)
    {
        cout << "\nMove Disk " << N << " from " << Src << " to " << Dest <<endl;
        return 0;
    }
       TOH(N - 1, Src, Dest, Aux);
   cout << "\nMove Disk " << N << " from " << Src << " to " << Dest << endl;

   TOH(N - 1, Aux, Src, Dest);
}

PROGRAM FOR TABLE OF NUMBER using RECURSION.



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

using namespace std;

int Table(int A, int B);

int main()
{
    int I = 1 ,No;

    cout << "Enter Any Number: ";
    cin >> No;

    cout << "\nThis is a Function returning Value: " << Table(No, 10) <<endl;

    getch();
    return 0;
}

int Table(int A, int B)
{
    if(B == 1)
    {
        cout << A << " * " << B << " = " << A * B << endl;
        return 1;
    }

    Table(A, B-1);
    cout << A << " * " << B << " = " << A * B << endl;

    return 25;
}

PRINT ARRAY ELEMENTS IN REVERSE ORDER using RECURSION.



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

using namespace std;

int Reverse(int *Arr, int No);

int main()
{
    int Size = 10;
    int *Arr = new int[Size];

    cout << "Enter Elements Of Array is:  " << endl;

    for(int I =1; I <=Size; I++)
    {
        Arr[I] = I;

        cout << Arr[I] << endl;
    }

    cout << "\nThis Function Returning Value: " << Reverse(Arr, Size) << endl;

    getch();
    return 0;
}

int Reverse(int *Arr, int No)
{
    if(No <= 0)
    return 1;

    cout << "Index No: "<< No << " Value: " <<  Arr[No]   << endl;

    return Reverse(Arr, No -1) ;
}

PROGRAM FOR POWER using RECURSION.



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

using namespace std;

long Power(int A, int B);

int main()
{
int No, Pow;

cout << "Enter Any Number: ";
cin >> No;

cout << "Power of Number is: ";
cin >> Pow;

cout << "\nResult is: " << Power(No, Pow) << endl;

getch();
return 0;
}

long Power(int A, int B)
{
long Result;

if (B == 1)
return A;

Result = A * Power(A, B - 1);
return Result;
}

PROGRAM FOR FACTORIAL using RECURSION.



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

using namespace std;

long Fact(int Num);

int main()
{
int No;

cout << "Enter Any Number: ";
cin >> No;

cout << "\nFactorial Of Given Number is: " << Fact(No) << endl;

getch();
return 0;
}

long Fact(int Num)
{
long Result;

if (Num == 1)
return 1;

Result = Num * Fact(Num - 1);
return Result;
}

PROGRAM FOR FABIONCCI SERIES using RECURSION.



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

using namespace std;

int Fabionnci(int A);

int main()
{
    int I = 1 ,No;

    cout << "Enter Any Number: ";
    cin >> No;

    while(I <= No)
    {
      cout << Fabionnci(I) << endl;
      I++;
    }

    getch();
    return 0;
}

int Fabionnci(int A)
{
    if(A == 0 || A == 1)
        return A;

    else
        return Fabionnci(A -1) + Fabionnci(A -2);
}

PROGRAM FOR BINARY SEARCH USING RECURSION.



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

using namespace std;

int B_Search(int *Arr, int No, int Beg, int End );

int main()
{
    int  *Array, Value, Size = 10;

    Array = new int[Size];

    for(int I = 0; I <Size; I++)
        Array[I] = I +1;

    cout << "Enter Value You Want To Search: ";
    cin >> Value;

    if(B_Search(Array, Value, 0, Size -1)  <0)
        cout << "\nValue Not Found!!!! " << endl;

    else
        cout << "Value Find At Index: " << B_Search(Array, Value, 0, Size -1) << endl;

    getch();
    return 0;
}

int B_Search(int *Arr, int No, int Beg, int End )
{
    int Mid = (Beg + End) /2;

    if(Beg >End)
        return -1;

    else if(Arr[Mid] == No)
        return Mid;

    else if(Arr[Mid] < No)
        B_Search(Arr, No, Mid+1, End);

        else
            B_Search(Arr, No, Beg, Mid-1);
}

PROGRAM TO GET SUM OF ARRAY ELEMENTS using RECURSION.



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

using namespace std;

long Sum(int *Arr, int No);

int main()
{
    int Size = 10;
    int *Arr = new int[Size];

    cout << "Enter Elements Of Array is:  " << endl;

    for(int I =1; I <=Size; I++)
    {
        Arr[I] = I;

        cout << Arr[I] << endl;
    }

    cout <<"\nSum of Array is: " << Sum(Arr, Size) << endl;

    getch();
    return 0;
}

long Sum(int *Ptr, int No)
{
        long Result;

    if(No <= 0)
        return 0;

    Result = Ptr[No] + Sum(Ptr, No -1) ;
    return Result;
}

PROGRAM FOR SIMPLEST QUEUE.



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

using namespace std;

template <class Type>

class Queue
{
private:
Type *Arr;
int Front, Rear, Size;

public:
Queue(int Siz)
{
Siz = Size;

Arr = new Type[Size];

Front = Rear = -1;
}

void EnQueue(Type Ch)
{
if (IsFull())
{
cout << "\nQueue OverFlowed!!!\n" << endl;
exit(1);
}

Arr[++Rear] = Ch;
}

Type dQueue()
{
if (IsEmpty())
{
cout << "\nQueue UnderFlowed!!!\n" << endl;
exit(1);
}

return Arr[++Front];
}

inline bool IsFull()
{
return Rear == Size - 1;
}

inline bool IsEmpty()
{
return Rear == Front;
}
};

int main()
{
Queue<int> Obj(100);

Obj.EnQueue(1);
Obj.EnQueue(2);
Obj.EnQueue(3);
Obj.EnQueue(4);
Obj.EnQueue(5);

for (int I = 0; I < 5; I++)
cout << Obj.dQueue() << endl;

getch();
return 0;
}

///Drawback Of Simplest Queue is We cannot reuse the Index Of Queue from which value has been Deleted.///
///It Can Be Improved If we Shift All Elements One Down.///

PROGRAM FOR QUEUE BY MOVING ELEMENTS ONE DOWN.



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

using namespace std;

template <class Type>

class Queue
{
private:
Type *Arr;
int Size, Front;

public:
Queue(int Siz)
{
Size = Siz;

Arr = new Type[Siz];

Front = -1;
}

void EnQueue(Type Ch)
{
if (IsFull())
{
cout << "\nQueue Overflowed!!!\n" << endl;
exit(1);
}

Arr[++Front] = Ch;
}

Type dQueue()
{
if (IsEmpty())
{
cout << "\nQueue UnderFlowed!!!\n" << endl;
exit(1);
}

char Ch = Arr[0];

for (int I = 1; I <= Front; I++)
Arr[I -1] = Arr[I];

        Front--;

return Ch;
}

inline bool IsEmpty()
{
return Front == -1;
}

inline bool IsFull()
{
return Front == Size - 1;
}
};

int main()
{
Queue<int> Obj(100);

Obj.EnQueue(1);
Obj.EnQueue(2);
Obj.EnQueue(3);
Obj.EnQueue(4);
Obj.EnQueue(5);

for (int I = 0; I < 5; I++)
cout << Obj.dQueue() << endl;

getch();
return 0;
}

///DRAWBACK OF QUEUE By Moving One Down IS COMPLEXITY INCREASES WITH THE INCREASE IN SIZE.///
///It can be Improved If we consider our Queue as Circular.///

PROGRAM FOR DeQUEUE.



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

using namespace std;

template <class Type>

class DeQueue
{
private:
Type *Queue;
int Size, Front, Rear, Count;

public:
DeQueue(int Siz)
{
Size = Siz;
Queue = new Type[Size];

Front = Count = -1;
Rear = Size - 1;
}

void EnQueue_Beg(Type Ch)
{
if (IsFull())
{
cout << "\nSTACK OVERFLOWED...!!!\n" << endl;
exit(1);
}

Count++;
Queue[++Front] = Ch;
}

void EnQueue_End(Type Ch)
{
if (IsFull())
{
cout << "\nSTACK OVERFLOWED...!!!\n" << endl;
exit(1);
}

Count++;
Queue[Rear--] = Ch;
}

Type dQueue_Beg()
{
if (IsEmpty())
{
cout << "\nSTACK UNDERFLOWED...!!!\n" << endl;
exit(1);
}

Count--;
return Queue[Front--];
}

Type dQueue_End()
{
if (IsEmpty())
{
cout << "\nSTACK UNDERFLOWED...!!!\n" << endl;
exit(1);
}

Count--;
return Queue[++Rear];
}

inline bool IsFull()
{
return Count == Size - 1;
}

inline bool IsEmpty()
{
return Count == -1;
}
};

int main()
{
DeQueue<int> Obj(10);

Obj.EnQueue_Beg(1);
Obj.EnQueue_End(99);

cout << "Element From Beginning: " << Obj.dQueue_Beg() << endl;
cout << "Element From End: " << Obj.dQueue_End() << endl;

getch();
return 0;
}

PROGRAM FOR CIRCULAR QUEUE.



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

using namespace std;

template <class Type>

class Queue
{
private:
Type *Arr;
int Front, Rear, Size;

public:
Queue(int Siz)
{
Size = Siz;

Arr = new Type[Size];

Front = Rear = Size - 1;
}

void EnQueue(Type Ch)
{
int Temp = (Rear + 1) % Size;
if (Temp == Front)
{
cout << "\nQueue OverFlowed..!!!\n" << endl;
exit(1);
}

Rear = (Rear + 1) % Size;
Arr[Rear] = Ch;
}

Type dQueue()
{
if (IsEmpty())
{
cout << "\nStack UnderFlowed..!!!\n" << endl;
exit(1);
}

Front = (Front + 1) % Size;
return Arr[Front];
}

inline bool IsEmpty()
{
return Front == Rear;
}
};

int main()
{
Queue<int> Obj(10);

Obj.EnQueue(1);
Obj.EnQueue(2);
Obj.EnQueue(3);
Obj.EnQueue(4);
Obj.EnQueue(5);

for (int I = 0; I < 5; I++)
cout << Obj.dQueue() << endl;

getch();
return 0;
}

PRIORITY QUEUE IN DESCENDING ORDER USING SORTING TECHNIQUES.



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

using namespace std;

template <class Type>

class PQueue
{
private:
Type *Queue;
int Size, Rear;

public:
PQueue(int Siz)
{
Size = Siz;

Queue = new Type[Size];

Rear = -1;
}

void EnQueue(Type Ch)
{
if (IsFull())
{
cout << "\nQueue OverFlowed...!!!\n" << endl;
exit(1);
}

Queue[++Rear] = Ch;
}

Type dQueue()
{
if (IsEmpty())
{
cout << "\nQueue Underflowed...!!!\n" << endl;
exit(1);
}

///Bubble_Sort(Queue);
Select_Sort(Queue);

Type Value = Queue[0];

for (int I = 0; I < Rear; I++)
Queue[I] = Queue[I + 1];

Rear--;
return Value;
}

void Select_Sort(Type *Arr)
{
int Max, Temp;

for (int I = 0; I <= Rear - 1; I++)
{

for (int J = I + 1; J <= Rear; J++)
{
if (Arr[J] > Arr[I])
{
Max = J;

Temp = Arr[I];
Arr[I] = Arr[Max];
Arr[Max] = Temp;
}
}
}
}

void Bubble_Sort(Type *Arr)
{
int Temp;

for (int I = 0; I < Rear - 1; I++)
{
for (int J = 0; J <= Rear - I - 1; J++)
{
if (Arr[J] < Arr[J + 1])
{
Temp = Arr[J];
Arr[J] = Arr[J + 1];
Arr[J + 1] = Temp;
}
}
}
}

inline bool IsEmpty()
{
return (Rear == -1);
}

inline bool IsFull()
{
return (Rear == Size - 1);
}
};

int main()
{
PQueue<int> Obj(10);

Obj.EnQueue(4);
Obj.EnQueue(5);
Obj.EnQueue(1);
Obj.EnQueue(3);
Obj.EnQueue(2);

for(int I = 0; I < 5; I++)
     cout << Obj.dQueue() << endl;

getch();
return 0;
}

PRIORITY QUEUE IN ASCENDING ORDER USING SORTING TECHNIQUES.



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

using namespace std;

template <class Type>

class PQueue
{
private:
Type *Queue;
int Size, Rear;

public:
PQueue(int Siz)
{
Size = Siz;

Queue = new Type[Size];

Rear = -1;
}

void EnQueue(Type Ch)
{
if (IsFull())
{
cout << "\nQueue OverFlowed...!!!\n" << endl;
exit(1);
}

Queue[++Rear] = Ch;
}

Type dQueue()
{
if (IsEmpty())
{
cout << "\nQueue Underflowed...!!!\n" << endl;
exit(1);
}

Bubble_Sort(Queue);
///Select_Sort(Queue);

Type Value = Queue[0];

for (int I = 0; I < Rear; I++)
Queue[I] = Queue[I + 1];

Rear--;
return Value;
}

void Select_Sort(Type *Arr)
{
int Min, Temp;

for (int I = 0; I <= Rear - 1; I++)
{

for (int J = I + 1; J <= Rear; J++)
{
if (Arr[J] < Arr[I])
{
Min = J;

Temp = Arr[I];
Arr[I] = Arr[Min];
Arr[Min] = Temp;
}
}
}
}

void Bubble_Sort(Type *Arr)
{
int Temp;

for (int I = 0; I < Rear - 1; I++)
{
for (int J = 0; J <= Rear - I - 1; J++)
{
if (Arr[J] > Arr[J + 1])
{
Temp = Arr[J];
Arr[J] = Arr[J + 1];
Arr[J + 1] = Temp;
}
}
}
}

inline bool IsEmpty()
{
return (Rear == -1);
}

inline bool IsFull()
{
return (Rear == Size - 1);
}
};

int main()
{
PQueue<int> Obj(10);

Obj.EnQueue(4);
Obj.EnQueue(5);
Obj.EnQueue(1);
Obj.EnQueue(3);
Obj.EnQueue(2);

for (int I = 0; I < 5; I++)
cout << Obj.dQueue() << endl;

getch();
return 0;
}

PROGRAM FOR PRIORITY QUEUE FOR DESCENDING ORDER.



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

using namespace std;

template <class Type>

class PQueue
{
private:
Type *Queue;
int Size, Rear;

public:
PQueue(int Siz)
{
Size = Siz;

Queue = new Type[Siz];

Rear = -1;
}

void EnQueue(Type Ch)
{
if (Rear == Size - 1)
{
cout << "\nQueue OverFlowed!!!\n" << endl;
exit(1);
}

Queue[++Rear] = Ch;
}

Type dQueue()
{
int Index = Maxi();
Type Value = Queue[Index];

if (IsEmpty())
{
cout << "\nQueue UnderFlowed!!!\n" << endl;
exit(1);
}

for (int I = Index; I <= Rear; I++)
Queue[I] = Queue[I + 1];

Rear--;
return Value;
}

inline bool IsEmpty()
{
return (Rear == -1);
}

int Maxi()
{
int Index;
Type Big = Queue[0];

for (int I = 1; I <= Rear; I++)
{
if (Big < Queue[I])
{
Index = I;
Big = Queue[I];
}
}

return Index;
}
};

int main()
{
PQueue<int> Obj(10);

Obj.EnQueue(3);
Obj.EnQueue(5);
Obj.EnQueue(7);
Obj.EnQueue(8);
Obj.EnQueue(1);

for (int I = 0; I < 5; I++)
cout << Obj.dQueue() << endl;

getch();
return 0;
}

PROGRAM FOR PRIORITY QUEUE FOR ASCENDING ORDER.



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

using namespace std;

template <class Type>

class PQueue
{
private:
Type *Queue;
int Size, Rear;

public:
PQueue(int Siz)
{
Size = Siz;

Queue = new Type[Siz];

Rear = -1;
}

void EnQueue(Type Ch)
{
if (Rear == Size - 1)
{
cout << "\nQueue OverFlowed!!!\n" << endl;
exit(1);
}

Queue[++Rear] = Ch;
}

void dQueue()
{
int Index = Mini();
Type Value = Queue[Index];

if (IsEmpty())
{
cout << "\nQueue UnderFlowed!!!\n" << endl;
exit(1);
}

for (int I = Index; I < Rear; I++)
Queue[I] = Queue[I + 1];

Rear--;
cout<<Value<<endl;
}

inline bool IsEmpty()
{
return (Rear == -1);
}

int Mini()
{
int Index;
Type Small = Queue[0];

for (int I = 1; I <= Rear; I++)
{
if (Small > Queue[I])
{
Index = I;
Small = Queue[I];
}
}

return Index;
}
};

int main()
{
PQueue<int> Obj(10);

Obj.EnQueue(3);
Obj.EnQueue(5);
Obj.EnQueue(7);
Obj.EnQueue(8);
Obj.EnQueue(1);

for (int I = 0; I < 5; I++)
Obj.dQueue() << endl;

getch();
return 0;
}

CONVERTING INFIX EXPRESSION INTO PREFIX EXPRESSION.



#include <bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <cctype>
#include <stdlib.h>
#include <conio.h>

using namespace std;

template <class Type>

class Infix2Prefix
{
private:
    Type *Stack;
    int Size, Top;

public:
    Infix2Prefix(int Siz)
    {
        Size = Siz;

        Stack = new Type[Size];
        strcpy(Stack, "\0");

        Top = -1;
    }

    void Push(Type Ch)
    {
        if( IsFull() )
        {
            cout << "\nSTACK OVERFLOWED!!!!!!!!!\n" << endl;
            exit(1);
        }

        Stack[++Top] = Ch;
    }

    Type Pop()
    {
        if( IsEmpty() )
        {
            cout << "\nSTACK UNDERFLOWED!!!!!!\n" << endl;
            exit(1);
        }

        return Stack[Top--];
    }

    Type TOP()
    {
        return Stack[Top];
    }

    bool IsOperator(char Ch)
    {
        return ( !isalpha(Ch) && !isdigit(Ch) );
    }

    int Priority(char Ch)
    {
        if(Ch == '^')
            return 3;

       else if( Ch == '*' || Ch == '/' )
            return 2;

        else if(Ch == '+' || Ch == '-')
            return  1;

            return 0;
    }

    string Convert(string Infix)
    {
        char Ch;
        string Prefix;

        reverse( Infix.begin(), Infix.end() );

        for(int I =0; I <Infix.length(); I++)
        {
            if( Infix[I] == '(' )
                Infix[I++] = ')';

            else if( Infix[I] == ')' )
                Infix[I++] = '(';
        }

        for(int I =0; I <Infix.length(); I++)
        {
            Ch = Infix[I];

            if( isalpha(Ch) || isdigit(Ch) )
                Prefix += Ch;

            else if( Ch == '(' )
                    Push(Ch);

            else if( Ch == ')' )
            {
                for(; TOP() !='(';)
                {
                    Prefix += Pop();
                }

                Pop();
            }

            else
            {
                if(IsOperator( TOP() ) )
                   {
                       while( Priority(Ch) <= Priority( TOP() ) )
                             {
                                 Prefix += Pop();
                             }

                             Push(Ch);
                    }
            }
}

Prefix += Pop();

reverse(Prefix.begin(), Prefix.end());

        return Prefix;
    }

    inline bool IsFull()
    {
        return (Top == Size - 1);
    }

    inline bool IsEmpty()
    {
        return (Top == -1);
    }

    ~Infix2Prefix()
    {
        cout << "\n\n\n****************PROGRAM ENDED*******************\n\n\n" << endl;
    }
};

int main()
{
    Infix2Prefix<char> Obj(100);
    string Expression;

    cout << "Enter any INFIX Expression: ";
    cin >> Expression;

    cout << "\nExpression After Converting To PRETFIX is: " << Obj.Convert(Expression) << endl;

    getch();
    return 0;
}