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

0 comments:

Post a Comment