online compiler and debugger for c/c++

code. compile. run. debug. share.
Source Code    Language
#include <iostream> #include <memory> using namespace std; typedef void (*iter_func)(const string *data); void print_node(const string *); class MyNode { string data; unique_ptr<MyNode> next { nullptr }; public: MyNode(string data) { this->data = data; } bool eq(string data) { return this->data == data; } void iterate(iter_func func) { func(&this->data); if(this->next) { this->next->iterate(func); } } void insert(string data) { if(data < this->data) { unique_ptr<MyNode> old = move(this->next); this->next = unique_ptr<MyNode>(new MyNode(this->data)); this->data = data; this->next->next = move(old); } else { if(this->next) { this->next->insert(data); } else { this->next = unique_ptr<MyNode>(new MyNode(data)); } } } bool remove(string data) { if(!this->next) { return false; } if(this->next->eq(data)) { this->next = move(this->next->next); return true; } return this->next->remove(data); } unique_ptr<MyNode> split_after() { return move(this->next); } }; class MyList { unique_ptr<MyNode> head { nullptr }; public: MyList() { } void iterate(iter_func func) { if(this->head) { this->head->iterate(func); } } void insert(string data) { if(this->head) { this->head->insert(data); } else { this->head = unique_ptr<MyNode>(new MyNode(data)); } } bool remove(string data) { if(!this->head) { return false; } return false; if(this->head->eq(data)) { this->head = this->head->split_after(); return true; } return this->head->remove(data); } }; void print_node(const string *data) { cout << "data: " << *data << endl; } int main() { unique_ptr<MyList> list(new MyList()); cout << "first run (empty):" << endl; list->iterate(print_node); list->insert("tomato salad"); cout << "second run (1):" << endl; list->iterate(print_node); list->insert("french fries"); cout << "third run (2):" << endl; list->iterate(print_node); list->insert("potato salad"); cout << "fourth run (3):" << endl; list->iterate(print_node); list->insert("marinated manatee"); cout << "fifth run (4):" << endl; list->iterate(print_node); list->remove("marinated manatee"); cout << "sixth run (3):" << endl; list->iterate(print_node); return 0; }

Compiling Program...

Command line arguments:
Standard Input: Interactive Console Text
×

                

                

Program is not being debugged. Click "Debug" button to start program in debug mode.

#FunctionFile:Line
VariableValue
RegisterValue
ExpressionValue