-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0950379
commit bc02322
Showing
8 changed files
with
422 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
///* | ||
// * ILinkList.cpp | ||
// * | ||
// * Created on: Jan 16, 2012 | ||
// * Author: option0417 | ||
// */ | ||
// | ||
//#include "ILinkedList.h" | ||
// | ||
//template <typename T> | ||
//ILinkedList<T>::ILinkedList() { | ||
// topNode = 0; | ||
// currNode = 0; | ||
// node = 0; | ||
// _size = 0; | ||
//} | ||
// | ||
//template <typename T> | ||
//ILinkedList<T>::ILinkedList(int size) : _size(size){ | ||
// if (_size > 1) { | ||
// node = new INode(); | ||
// node->val = 0; | ||
// node->ptr = 0; | ||
// | ||
// topNode = node; | ||
// currNode = node; | ||
// } | ||
// | ||
// | ||
// for (int cnt = 1; cnt < _size; cnt++) { | ||
// node = new INode(); | ||
// node->val = 0; | ||
// node->ptr = 0; | ||
// currNode->ptr = node; | ||
// currNode = node; | ||
// } | ||
//} | ||
// | ||
//template <typename T> | ||
//ILinkedList<T>::~ILinkedList() { | ||
// while (topNode != 0) { | ||
// INode *tmp = topNode; | ||
// topNode = topNode->ptr; | ||
// delete tmp; | ||
// } | ||
//} | ||
// | ||
//template <typename T> | ||
//void ILinkedList<T>::add(T val) { | ||
// node = new INode(); | ||
// node->val = val; | ||
// node->ptr = 0; | ||
// | ||
// currNode->ptr = node; | ||
// currNode = node; | ||
//} | ||
// | ||
//template <typename T> | ||
//void ILinkedList<T>::remove(int index) { | ||
// | ||
//} | ||
// | ||
//template <typename T> | ||
//T ILinkedList<T>::get(int index) { | ||
// if (topNode != 0) { | ||
// node = topNode; | ||
// } | ||
// | ||
// while (index > 0) { | ||
// node = node->ptr; | ||
// | ||
// if (node == 0) { | ||
// return 0; | ||
// } | ||
// | ||
// index--; | ||
// } | ||
// | ||
// return node; | ||
//} | ||
// | ||
//template <typename T> | ||
//int ILinkedList<T>::size() { | ||
// return _size; | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
/* | ||
* ILinkedList.h | ||
* | ||
* Created on: Jan 16, 2012 | ||
* Author: option0417 | ||
*/ | ||
|
||
#ifndef ILINKEDLIST_H_ | ||
#define ILINKEDLIST_H_ | ||
|
||
|
||
#include <iostream> | ||
|
||
template <typename T> | ||
class ILinkedList { | ||
public: | ||
ILinkedList(); | ||
ILinkedList(int); | ||
virtual ~ILinkedList(); | ||
|
||
void add(T); | ||
void remove(int); | ||
T get(int); | ||
int size(); | ||
|
||
private: | ||
struct INode{ | ||
T val; | ||
INode *ptr; | ||
int position; | ||
}; | ||
|
||
struct INode *topNode; | ||
struct INode *currNode; | ||
struct INode *node; | ||
int _size; | ||
}; | ||
|
||
template <typename T> | ||
ILinkedList<T>::ILinkedList() { | ||
topNode = 0; | ||
currNode = 0; | ||
node = 0; | ||
_size = 0; | ||
} | ||
|
||
template <typename T> | ||
ILinkedList<T>::ILinkedList(int size) : _size(size){ | ||
if (_size > 1) { | ||
node = new INode(); | ||
node->val = 0; | ||
node->ptr = 0; | ||
node->position = 0; | ||
|
||
topNode = node; | ||
currNode = node; | ||
} | ||
|
||
|
||
for (int cnt = 1; cnt < _size; cnt++) { | ||
node = new INode(); | ||
node->val = 0; | ||
node->ptr = 0; | ||
node->position = cnt; | ||
currNode->ptr = node; | ||
currNode = node; | ||
} | ||
} | ||
|
||
template <typename T> | ||
ILinkedList<T>::~ILinkedList() { | ||
while (topNode != 0) { | ||
INode *tmp = topNode; | ||
topNode = topNode->ptr; | ||
delete tmp; | ||
} | ||
} | ||
|
||
template <typename T> | ||
void ILinkedList<T>::add(T val) { | ||
_size++; | ||
node = new INode(); | ||
node->val = val; | ||
node->ptr = 0; | ||
node->position = _size - 1; | ||
|
||
if (_size == 1) { | ||
topNode = node; | ||
currNode = node; | ||
} else { | ||
currNode->ptr = node; | ||
currNode = node; | ||
} | ||
} | ||
|
||
template <typename T> | ||
void ILinkedList<T>::remove(int index) { | ||
|
||
} | ||
|
||
template <typename T> | ||
T ILinkedList<T>::get(int index) { | ||
if (topNode != 0) { | ||
node = topNode; | ||
} | ||
|
||
while (index > 0) { | ||
node = node->ptr; | ||
|
||
if (node == 0) { | ||
return 0; | ||
} | ||
|
||
index--; | ||
} | ||
|
||
return node->val; | ||
} | ||
|
||
template <typename T> | ||
int ILinkedList<T>::size() { | ||
return _size; | ||
} | ||
|
||
#endif /* ILINKEDLIST_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
/* | ||
* INode.h | ||
* | ||
* Created on: Jan 17, 2012 | ||
* Author: option0417 | ||
*/ | ||
|
||
#ifndef INODE_H_ | ||
#define INODE_H_ | ||
|
||
//template <typename T> | ||
class INode { | ||
public: | ||
int val; | ||
INode *ptr; | ||
}; | ||
|
||
|
||
#endif /* INODE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
/* | ||
* MongoSample.cpp | ||
* | ||
* Created on: Jan 16, 2012 | ||
* Author: option0417 | ||
*/ | ||
|
||
#include "MongoSample.h" | ||
|
||
MongoSample::MongoSample() { | ||
// TODO Auto-generated constructor stub | ||
|
||
} | ||
|
||
MongoSample::~MongoSample() { | ||
// TODO Auto-generated destructor stub | ||
} | ||
|
||
void MongoSample::run() { | ||
try { | ||
DBClientConnection c; | ||
c.connect("localhost"); //"192.168.58.1"); | ||
std::cout << "connected ok" << std::endl; | ||
BSONObj p = BSON( "name" << "Joe" << "age" << 33 ); | ||
c.insert("tutorial.persons", p); | ||
p = BSON( "name" << "Jane" << "age" << 40 ); | ||
c.insert("tutorial.persons", p); | ||
p = BSON( "name" << "Abe" << "age" << 33 ); | ||
c.insert("tutorial.persons", p); | ||
p = BSON( "name" << "Samantha" << "age" << 21 << "city" << "Los Angeles" << "state" << "CA" ); | ||
c.insert("tutorial.persons", p); | ||
|
||
c.ensureIndex("tutorial.persons", fromjson("{age:1}")); | ||
|
||
cout << "count:" << c.count("tutorial.persons") << endl; | ||
|
||
auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", BSONObj()); | ||
while( cursor->more() ) { | ||
cout << cursor->next().toString() << endl; | ||
} | ||
|
||
cout << "\nprintifage:\n"; | ||
printIfAge(c, 33); | ||
} catch( DBException &e ) { | ||
std::cout << "caught " << e.what() << std::endl; | ||
} | ||
} | ||
|
||
|
||
void MongoSample::printIfAge(DBClientConnection& c, int age) { | ||
auto_ptr<DBClientCursor> cursor = c.query("tutorial.persons", QUERY( "age" << age ).sort("name") ); | ||
while( cursor->more() ) { | ||
BSONObj p = cursor->next(); | ||
cout << p.getStringField("name") << endl; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* MongoSample.h | ||
* | ||
* Created on: Jan 16, 2012 | ||
* Author: option0417 | ||
*/ | ||
|
||
#ifndef MONGOSAMPLE_H_ | ||
#define MONGOSAMPLE_H_ | ||
|
||
#include <iostream> | ||
#include "mongo/client/dbclient.h" | ||
|
||
using namespace mongo; | ||
|
||
class MongoSample { | ||
public: | ||
MongoSample(); | ||
virtual ~MongoSample(); | ||
|
||
void run(); | ||
|
||
private: | ||
void printIfAge(DBClientConnection& , int ); | ||
}; | ||
|
||
#endif /* MONGOSAMPLE_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* RandomArray.cpp | ||
* | ||
* Created on: Jan 15, 2012 | ||
* Author: option0417 | ||
*/ | ||
|
||
#include "RandomVector.h" | ||
|
||
RandomVector::RandomVector() :size(0) { | ||
init(); | ||
} | ||
|
||
RandomVector::RandomVector(int size) :size(size) { | ||
init(); | ||
} | ||
|
||
RandomVector::~RandomVector() { | ||
intVector->clear(); | ||
delete intVector; | ||
size = 0; | ||
} | ||
|
||
std::vector<int>* RandomVector::getVector() { | ||
return intVector; | ||
} | ||
|
||
void RandomVector::show() { | ||
for (int i = 0; i < size; i++) { | ||
std::cout<<intVector->at(i)<<" "; | ||
} | ||
std::cout<<std::endl; | ||
} | ||
|
||
void RandomVector::init() { | ||
srand(time(NULL)); | ||
intVector = new std::vector<int>(); | ||
intVector->reserve(size); | ||
|
||
for (int i = 0; i < size; i++) { | ||
intVector->push_back((int)rand() % 100 + 1); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/* | ||
* RandomVector.h | ||
* | ||
* Created on: Jan 15, 2012 | ||
* Author: option0417 | ||
*/ | ||
|
||
#ifndef RANDOMVECTOR_H_ | ||
#define RANDOMVECTOR_H_ | ||
|
||
#include <vector> | ||
#include <iostream> | ||
#include <cstdlib> | ||
#include <ctime> | ||
|
||
class RandomVector { | ||
public: | ||
RandomVector(); | ||
RandomVector(int); | ||
virtual ~RandomVector(); | ||
|
||
std::vector<int>* getVector(); | ||
void show(); | ||
private: | ||
std::vector<int> *intVector; | ||
int size; | ||
|
||
void init(); | ||
}; | ||
|
||
#endif /* RANDOMVECTOR_H_ */ |
Oops, something went wrong.