排不了序
插入排序.h
#ifndef INSERTSORT_H
#define INSERTSORT_H
#include <vector>
using namespace std;
class InsertSort
{
private:
int len;
vector<int>list(3);
public:
InsertSort(vector<int>_list,int _len);
void Insert_sort();
void out();
};
#endif
我写主函数调用
#include<iostream>
#include<vector>
#include"插入排序.h"
using namespace std;
int main()
{
vector<int>test(3);
cout << "请输入数字: " <<endl;
for(int i=0; i< 3; i++)
cin >> test[i];
InsertSort test_sort(test,test.size());//test.size()值有问题!!
test_sort.Insert_sort();
test_sort.out();
return 0;
}
vector<int>test(3);//一定要指定大小比如(3)吗?
为什么排不了序呢?//插入排序.cpp实现代码没问题的。
[解决办法]
- C/C++ code
vector( ); explicit vector( const Allocator& _Al);explicit vector( size_type _Count);vector( size_type _Count, const Type& _Val);vector( size_type _Count, const Type& _Val, const Allocator& _Al);vector( const vector<Type, Allocator>& _Right);template<class InputIterator> vector( InputIterator _First, InputIterator _Last );template<class InputIterator> vector( InputIterator _First, InputIterator _Last, const Allocator& _Al );
[解决办法]
[解决办法]
把自己的数据量设置小点,然后单步调试,一个语句一个语句看。肯定能知道哪里出错的。