C++ 无法从排序类c+;访问元素+;
嘿,我目前正在做一个家庭作业,我们比较不同种类的数据以提高效率。然而,我在访问数据元素时遇到困难,感觉有点傻,因为我觉得这应该是一个简单的答案。这是我的主要功能C++ 无法从排序类c+;访问元素+;,c++,arrays,C++,Arrays,嘿,我目前正在做一个家庭作业,我们比较不同种类的数据以提高效率。然而,我在访问数据元素时遇到困难,感觉有点傻,因为我觉得这应该是一个简单的答案。这是我的主要功能 int main() { //declarations int const MYARRAYSIZE = 100; Sort mySort(MYARRAYSIZE); mySort.init_array(); clock_t timeA = clock(); for(int i
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");
}
intmain()
{
//声明
int const MYARRAYSIZE=100;
排序mySort(MYARRAYSIZE);
mySort.init_数组();
clock_t timeA=时钟();
for(int i=0;i
这是我的头
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();
};
类排序
{
私人:
整数大小;
int*myArray;
公众:
排序(整数大小);
~Sort();
friend ostream&operator/*Whatgoesher*/
那里什么都没有
从成员函数中删除参数
例如:
只需使用:
void insertion\u sort();
这知道它的myArray
和size
,因为它们是类的数据成员
简单地称之为
mySort.insertion\u sort();
这考虑到您的所有成员函数都是使用myArray
和size
正确实现的。如果数组已经是一个成员,为什么它是一个参数?哇,谢谢。我想我真的很困惑,因为在书中它们有参数。这一切现在都有意义了。对于noob问题,很抱歉。