0
我初學編程的,並試圖獲得此代碼的工作:需要幫助的這個C++代碼
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
T min(vector<T>vec) {
T x=vec[0];
int index;
for (int i=0; i<vec.size(); i++) {
if (vec[i]<x) { x=vec[i]; index=i; }
}
return index;
}
template <typename T>
void printVec (vector<T>v) {
for (int i=0; i<v.size(); i++)
cout<<v[i]<<endl;
}
template <typename T>
void selectSort(vector<T>&first) {
vector<T>second;
while(first.size()!=0) {
second.push_back(first[min(first)]);
first.erase(first.begin()+min(first));
}
first=second;
}
int main() {
int Mas[] = { 7, 15, 14, 12, 99, 180, 197, 567, 123, -101, 32, 144, 156, 177, 4, -17, -88, 18, 99, 143, -90 };
int dim = sizeof(Mas)/sizeof(int);
vector<int>v (&Mas[0], &Mas[dim]);
int m=min(v);
selectSort(v);
printVec(v);
cin.get();
return 0; }
出於某種原因,
while(first.size()!=0) {
循環似乎並沒有工作。 有人可以幫忙嗎? 對不起,我的英語不好。
你有沒有試過調試它,看看哪裏不行? – 2013-03-17 11:01:21
你應該把代碼放在這裏而不是pastebin,如果你的問題得到了回答,並且pastebin中的代碼稍後被取下,這個帖子對未來的用戶來說是完全沒有用的。 – 2013-03-17 11:02:44
對不起,但我不知道如何發佈整個代碼。 – 2013-03-17 11:04:56