Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
HTML Node
Language:
Ada
Assembly
Bash
C#
C++ (gcc)
C++ (clang)
C++ (vc++)
C (gcc)
C (clang)
C (vc)
Client Side
Clojure
Common Lisp
D
Elixir
Erlang
F#
Fortran
Go
Haskell
Java
Javascript
Kotlin
Lua
MySql
Node.js
Ocaml
Octave
Objective-C
Oracle
Pascal
Perl
Php
PostgreSQL
Prolog
Python
Python 3
R
Rust
Ruby
Scala
Scheme
Sql Server
Swift
Tcl
Visual Basic
Layout:
Vertical
Horizontal
/** 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; } }
g++
Show compiler warnings
[
+
] Compiler args
[
+
]
Show input
Compilation time: 0.43 sec, absolute running time: 0.07 sec, cpu time: 0.02 sec, memory peak: 3 Mb, absolute service time: 0,51 sec
fork mode
|
history
|
discussion
div4 div2 div2-end div1 div5 div5-end div1-end div4-end