-
June 10th, 2011, 07:55 AM
#1
Newbie question, insertSort algorithm
Hi guys, I'm trying to compile the following code in Visual Studio 2010 Express for a simple implementation of insertSort:
InsertSort.h
=========
template <class T>
void isort(const T& start, const T& end){
for (T i=start; i<end; ++i){
T::value_type value = *i;
T dec = i;
while(dec>start && *(dec-1) >= value){
*dec = *(dec-1);
--dec;
}
*dec = value;
}
}
ISMain.cpp
========
#include <iostream>
#include "InsertSort.h"
#include <vector>
int main() {
std::vector<double> vec(10, 0.0);
for (int i=0;i<vec.size();i++) {
vec[i] = rand();
}
isort(vec[0], vec[9]);
std::cout << "vector sorted" << std::endl;
return 0;
}
I'm getting a host of error messages:
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(3): warning C4067: unexpected tokens following preprocessor directive - expected a newline
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(7): error C2039: 'vector' : is not a member of 'std'
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(7): error C2065: 'vector' : undeclared identifier
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(7): error C2062: type 'double' unexpected
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(8): error C2065: 'x' : undeclared identifier
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(8): error C2228: left of '.size' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(9): error C2065: 'x' : undeclared identifier
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(9): error C2228: left of '.at' must have class/struct/union
1> type is ''unknown-type''
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(12): error C2065: 'x' : undeclared identifier
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(12): error C2065: 'x' : undeclared identifier
1>c:\users\hcm\documents\visual studio 2010\projects\insertsort\insertsort\ismain.cpp(12): error C3861: 'isort': identifier not found
I'm sure I'm making some obvious mistakes. Any help would be much appreciated!
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|