2018-10-30 18:26:36 +08:00
|
|
|
/**
|
|
|
|
* Created by Liam Huang (Liam0205) on 2018/10/30.
|
|
|
|
*/
|
|
|
|
|
2018-10-29 11:54:47 +08:00
|
|
|
#include <iostream>
|
2018-10-30 17:42:36 +08:00
|
|
|
#include <string>
|
|
|
|
|
2018-10-29 11:54:47 +08:00
|
|
|
#include "skiplist.hpp"
|
|
|
|
|
|
|
|
int main() {
|
2018-10-30 17:42:36 +08:00
|
|
|
// 1. Initialize a skip list for test
|
|
|
|
// * default constructor
|
|
|
|
// * constructor with initializer list
|
|
|
|
// * insert
|
|
|
|
skiplist<std::string> ss{"1", "2", "3", "4", "5"};
|
|
|
|
|
|
|
|
// 1a. show
|
|
|
|
// * print
|
|
|
|
ss.print(std::cout);
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
|
|
// 2. move construction
|
|
|
|
// * move constructor
|
|
|
|
skiplist<std::string> s(std::move(ss));
|
|
|
|
|
|
|
|
// 2a. show
|
|
|
|
// * print
|
|
|
|
s.print(std::cout);
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
|
|
// 3.a find something doesn't exist.
|
|
|
|
// * find
|
|
|
|
auto f = s.find("0");
|
|
|
|
if (!f.empty()) {
|
|
|
|
std::cout << "Node found!\nvalue: " << f << '\n';
|
|
|
|
} else {
|
|
|
|
std::cout << "Node NOT found!\n";
|
2018-10-29 11:54:47 +08:00
|
|
|
}
|
2018-10-30 17:42:36 +08:00
|
|
|
|
|
|
|
// 3.b find something does exist.
|
|
|
|
// * find
|
|
|
|
auto ff = s.find("1");
|
|
|
|
if (!ff.empty()) {
|
|
|
|
std::cout << "Node found!\tvalue: " << ff << '\n';
|
|
|
|
} else {
|
|
|
|
std::cout << "Node NOT found!\n";
|
|
|
|
}
|
|
|
|
|
|
|
|
// 4. insert() - reassign
|
|
|
|
s.insert("TEST");
|
|
|
|
|
|
|
|
// 4a. print()
|
|
|
|
s.print(std::cout);
|
|
|
|
std::cout << std::endl;
|
|
|
|
|
|
|
|
// 5. erase()
|
|
|
|
s.erase("TEST");
|
|
|
|
|
|
|
|
// 5a. print();
|
|
|
|
s.print(std::cout);
|
2018-10-29 11:54:47 +08:00
|
|
|
std::cout << std::endl;
|
|
|
|
|
2018-10-30 17:42:36 +08:00
|
|
|
std::cout << "\nDone!\n";
|
2018-10-30 11:06:35 +08:00
|
|
|
|
2018-10-29 11:54:47 +08:00
|
|
|
return 0;
|
2018-10-30 17:42:36 +08:00
|
|
|
// 6. destructor
|
2018-10-29 11:54:47 +08:00
|
|
|
}
|