Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
HTML Node
/** Samuel Ugochukwu Nwutobo sammycageagle@gmail.com 23 July 2019 HTML Node **/ #include <iostream> struct Node { Node(std::string n) : id(n){} std::string id; Node* parent; Node* next; Node* prev; Node* end; }; Node *createElement(std::string id) { Node* e = new Node(id); e->parent = e; e->end = new Node(id + "-end"); e->end->parent = e; e->end->prev = e; e->end->next = e; e->prev = e->end; e->next = e->end; return e; } enum InsertMode { EBeforeBegin, EAfterBegin, EBeforeEnd, EAfterEnd }; void insertElement(Node *head, Node *tail, Node* target, InsertMode mode) { head->prev = tail; tail->next = head; switch(mode) { case EBeforeBegin: { Node* targetPrev = target->prev; targetPrev->next = head; head->prev = targetPrev; target->prev = tail; tail->next = target; break; } case EAfterBegin: { Node* targetNext = target->next; target->next = head; head->prev = target; targetNext->prev = tail; tail->next = targetNext; break; } case EBeforeEnd: { target = target->end; Node* targetPrev = target->prev; targetPrev->next = head; head->prev = targetPrev; target->prev = tail; tail->next = target; break; } case EAfterEnd: { target = target->end; Node* targetNext = target->next; target->next = head; head->prev = target; targetNext->prev = tail; tail->next = targetNext; break; } } } void insertElement(Node* e, Node* target, InsertMode mode) { insertElement(e, e->prev, target, mode); } void appendElement(Node* e, Node* target) { insertElement(e, e->prev, target, EBeforeEnd); } int main() { Node* body = createElement("body"); Node* div1 = createElement("div1"); Node* div2 = createElement("div2"); Node* div3 = createElement("div3"); Node* div4 = createElement("div4"); Node* div5 = createElement("div5"); insertElement(div5, div1, EBeforeEnd); insertElement(div1, div4, EBeforeEnd); insertElement(div2, div1, EBeforeBegin); insertElement(div4, body, EBeforeEnd); Node* e = body->next; while(e != body->end) { std::cout << e->id << std::endl; e = e->next; } }
run
|
edit
|
history
|
help
0
Atul
ONP is working!
Best way for getting more precision no.
Count squares
GET ALL PRIME FACTORS OF A NUMBER
CyclicExpression Checker
NWD
2
Bitwise - Check power of 2 or not
Teatime Snack