algorithms

algorithms Commit Details


Date:2013-02-16 18:34:00 (11 years 10 months ago)
Author:Natalie Adams
Branch:default
Commit:e1a05c29b2c4
Parents: 019f5c4964fc
Message:Insertion sort is working

Changes:
Mcpp/algorithms/src/Algorithm.h (1 diff)
Mcpp/algorithms/src/InsertSort.h (1 diff)
Mcpp/algorithms/src/SearchAlgorithm.h (1 diff)
Mcpp/algorithms/src/SortAlgorithm.h (1 diff)
Mcpp/algorithms/src/main.cpp (1 diff)

File differences

cpp/algorithms/src/Algorithm.h
1010
1111
1212
13
1314
1415
1516
{
protected:
std::vector<T> _container;
//friend class SortAlgorithm;
public:
void initContainer(std::vector<T> arr)
{
cpp/algorithms/src/InsertSort.h
44
55
66
7
7
88
9
910
1011
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
1226
1327
1428
#include "SortAlgorithm.h"
template <class T>
class InsertSort : public SortAlgorithm<T>
class InsertSort : public SortAlgorithm, public Algorithm<T>
{
public:
virtual void Sort()
{
int x;
T currelement;
for(size_t i = 1; i < this->_container.size(); i++)
{
x = i - 1;
currelement = this->_container[i];
while(x >= 0 && _container[x] > currelement)
{
_container[x+1] = _container[x];
x = x - 1;
}
_container[x + 1] = currelement;
}
}
};
cpp/algorithms/src/SearchAlgorithm.h
33
44
55
6
7
6
87
98
9
1010
1111
1212
#include "Algorithm.h"
template <class T>
class SearchAlgorithm : public Algorithm
class SearchAlgorithm
{
public:
//void f() { this->
virtual void Search() = 0;
};
cpp/algorithms/src/SortAlgorithm.h
33
44
55
6
7
6
7
88
99
1010
#include "Algorithm.h"
template <class T>
class SortAlgorithm : public Algorithm<T>
class SortAlgorithm
{
public:
virtual void Sort() = 0;
cpp/algorithms/src/main.cpp
33
44
55
6
7
68
79
810
911
1012
13
1114
1215
13
16
17
1418
1519
#include "vector_helper.h"
#include <vector>
#include <string>
using namespace std;
int main()
{
InsertSort<int> sort1;
//sort1.initContainer(create_vector<string>("test")("test2"));
//cout << sort1.ToString();
//vector<int> arr1 = create_vector<int>(
sort1.initContainer(create_vector<int>(1)(2)(3));
sort1.initContainer(create_vector<int>(3)(2)(3));
sort1.Sort();
cout << sort1.ToString() << endl;
}

Archive Download the corresponding diff file

Branches

Tags

Page rendered in 0.41682s using 14 queries.