Chegg integer chickencount is read from input as the number of input values that follow. The node headchicken is created with the value of chickencount. Use cin to read chickencount integers. Insert a chickennode for each integer at the end of the linked list. Ex: if the input is 2 12 13, then the output is: 2 12 13



Answer :

The appropriate program to illustrate the information is given below.

How to illustrate the program?

Code(C++):

#include <iostream>

using namespace std;

class HorseNode

{

public:

HorseNode (int foalsInit = 0, HorseNode * nextLoc = nullptr);

void InsertAfter (HorseNode * nodeLoc);

HorseNode * GetNext ();

void PrintNodeData ();

private:

int foalsVal;

HorseNode * nextNodePtr;

};

int

main ()

{

HorseNode * headHorse = nullptr;

HorseNode * currHorse = nullptr;

HorseNode * lastHorse = nullptr;

int horseCount;

int inputValue;

int i;

cin >> horseCount;

headHorse = new HorseNode(horseCount);

lastHorse = headHorse;

/* Your code goes here */

for(int i =0;i<horseCount;i++){

int k;

cin>>k; // reading horse count intgers

HorseNode* newHorse = new HorseNode(k); // new horse with i'th horse count integer

lastHorse->InsertAfter(newHorse); //inert this after lastHorse

lastHorse = newHorse; // Set newly inserted horse as current lastHorse

}

currHorse = headHorse;

while (currHorse != nullptr)

{

currHorse->PrintNodeData ();

currHorse = currHorse->GetNext ();

}

return 0;

}

HorseNode:: HorseNode (int foalsInit, HorseNode * nextLoc)

{

this->foalsVal = foalsInit;

this->nextNodePtr = nextLoc;

}

void

HorseNode::InsertAfter (HorseNode * nodeLoc)

{

HorseNode * tmpNext = nullptr;

tmpNext = this->nextNodePtr;

this->nextNodePtr = nodeLoc;

nodeLoc->nextNodePtr = tmpNext;

}

HorseNode * HorseNode::GetNext ()

{

return this->nextNodePtr;

}

void

HorseNode::PrintNodeData ()

{

cout << this->foalsVal << endl;

}

Learn more about program on:

https://brainly.com/question/26642771

#SPJ1