0

嘿,我目前正在做一个家庭作业,我们比较不同种类的效率。但是我在访问数据元素时遇到了麻烦,并且感觉有点愚蠢,因为我觉得这应该是一个简单的答案。这是我的主要功能。

    int main()
{
    //declarations
    int const MYARRAYSIZE = 100;
    Sort mySort(MYARRAYSIZE);

    mySort.init_array();

    clock_t timeA = clock();
    for(int i = 0; i < MYARRAYSIZE; i++)
    {
        //run tests
        mySort.insertion_sort(/*whatgoeshere*/, MYARRAYSIZE );
    }
    clock_t timeB = clock();
    clock_t diff = timeB - timeA;

    system("PAUSE");
}

这是我的标题

class Sort
{
private:
    int size;
    int *myArray;
public:
    Sort(int size);
    ~Sort();
    friend ostream& operator << (ostream& out, const Sort& s)
    {
        //put code in here
    }
    void insertion_sort(int [], int);
    void selection_sort(int [], int);
    void merge_sort(int [], int);
    void quick_sort(int [], int);
    void partition(int [], int, int&);
    void merge(int [], int, int);
    void init_array();
    int getSize();
};

我正在尝试访问存储在 myArray 中的数组,并且我知道只有类可以访问它,但是我将如何访问它呢?

4

1 回答 1

1

/* whatgoeshere* /

Nothing goes there.

remove arguments from member functions

Example :

Just use:

void insertion_sort( );

This knows its myArray and size as they are data members of class

And simply call it as

mySort.insertion_sort( );

This considers your all member functions are implemented correctly using myArray and size.

于 2013-10-06T18:30:37.400 回答