DOUBLY LINK RANDOM NUMBER GENERATOR

How would I begin writing a function to fit these instructions?

1. Create an integer variable named ‘listSize’ and initialize the value to 1000.

2. Open an output file named ‘RESULTS.csv’. The first line of this file should be the column headings: ‘List Size’, ‘Selection Sort Data Swap Time’, ‘Selection Sort Node Swap Time’, ’Insertion Sort Node Swap Time’, ‘Quick Sort Node Swap Time’.

3. Using the rand () function, fill 4 doubly linked list of integers with the number of variables corresponding to the ‘listSize’ variable. The list should be created using the push operator. The values generated by rand () should be numbers from 1-500,000. The list should be named; selectionListData, selectionListNode, insertionListNode, and quickListNode.

PLEASE no bullying right now. If you don't want to help just close out of the forum.
How would I begin writing a function to fit these instructions?


1
2
3
4
int no_bullying()
{
    return 0;
}
Step one: define listSize as 1000. This you can do super easy, you have to admit that.
int listSize = 1000;
Step two: Open ... Time'.
Just use ofstream.
Step three: make your 4 lists. C++ has a <list> header, which I’m guessing you know; use that. The push documentation is here: (push front)http://www.cplusplus.com/reference/list/list/push_front/ (push back)http://www.cplusplus.com/reference/list/list/push_back/
 
list selectionListData, selectionListNode, insertionListNode, quickListNode; // obviously not really valid code, but you get it. 

> the number of variables corresponding to the ‘listSize’ variable.
So make 1000 rand #s each? for loop and some modding.

So, it would look like
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#include <fstream>
#include <list>
#include <cstdlib>

void function(){
  int listSize = 1000;
  // Just use ofstream. open file.
  list selectionListData, selectionListNode, insertionListNode, quickListNode; // obviously not really valid code, but you get it.
  // begin for
    // push random number into first list.
  // end for

  // begin for
    // push random number into second list.
  // end for

  // begin for
    // push random number into third list.
  // end for

  // begin for
    // push random number into fourth list.
  // end for
  
  return;
}

int main(){
  function();
}
Topic archived. No new replies allowed.