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

0 comments:

Post a Comment