For class, we are analyzing 4 different data structures. Each data structures holds randomly generated integers. Later, we compare them with Big-O, and give the advantages and disadvantages of each one.
It makes sense that each data structure contains the same integers, but how do I make sure they all have the same data?
Here's an example:
Abstract class...
CODE
#pragma once
#include <iostream>
#include <cstdlib> // random generation
#include <ctime> // random generation
using namespace std;
class AbstractStruct
{
public:
virtual int generate_data(int n) = 0;
virtual void sort_data(void) = 0;
};
This class is called vector_class, and in the vector_class.h file, I have this:
CODE
class vector_class: public AbstractStruct
In vector_class.cpp, I have:
CODE
int vector_class::generate_data(int n)
{
data_vector;
data_vector.reserve(n);
srand((unsigned)time(0));
for(int i = 0; i < n; i++)
{
int data = rand();
data = data<<15;
data+=rand();
data_vector.push_back(data);
cout << data_vector.at(i) << endl;
}
return 0;
}
How can I get the data to be the same?
Somehow I need to put data in AbstractStruct, but I'm not sure how to make sure each data structure gets the same data.
This post has been edited by COMMUNISTCHINA: 27 Sep, 2008 - 08:51 PM