I need to write a simple random number generator that inserts at the head(linked
ID: 640555 • Letter: I
Question
I need to write a simple random number generator that inserts at the head(linked list) using more than one function. (please show output). I alread wrote some of it.
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <fstream>
using namespace std;
struct nodetype
{
int num;
nodetype *next;
};
ifstream infile;
int main()
{
int digit;
nodetype *head = NULL;
nodetype *ptr;
nodetype *r;
ptr = new nodetype;
r = new nodetype;
while (!infile.eof())
{
infile >> digit;
if (head == NULL)
{
head = new nodetype;
head->num = digit;
head->next = NULL;
ptr = head;
}
else
{
r = new nodetype;
r->num = digit;
r->next = NULL;
ptr->next = r;
ptr = r;
}
}
void random();
}
void random()
{
srand(5000);
for (int count = 0; count < 20; count++)
{
cout << rand() << " ";
if ((count + 1) % 5 == 0)
cout << endl;
}
}