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;
}