7 namespace datastructure {
41 const string& lab =
string()) :
SLelement<E>(n, val, lab) {
53 DLelement (
const E& val = E(),
const string& lab =
string()) :
64 return "DoublyLinkedList";
90 if (this->
next != n && this->
next != prev) {
94 if ((this->
next = n)) {
119 if (prev != p && this->
next != prev) {
120 this->
links.erase(prev);
131 virtual const string getDataStructureRepresentation()
const override {
133 vector<const DLelement<E>*> nodes;
137 getListElements(nodes);
143 throw "Max allowed elements(for visualization) exceeded.. " +
144 to_string(nodes.size()) +
" Must be less than " +
151 unordered_map<const DLelement*, int> node_map { {
nullptr, -1} };
153 string nodes_JSON, links_JSON;
156 for (
const auto* e : nodes) {
157 if (node_map.emplace(e, i).second) {
160 nodes_JSON += e->getElementRepresentation() +
COMMA;
165 node_map.erase(
nullptr);
166 if (nodes_JSON.size()) {
167 nodes_JSON = nodes_JSON.erase(nodes_JSON.size() - 1);
171 for (
int k = 0; k < nodes.size(); k++) {
172 if (nodes[k]->
next !=
nullptr) {
174 to_string(node_map[nodes[k]]),
177 if (nodes[k]->prev !=
nullptr) {
179 to_string(node_map[nodes[k]]),
180 to_string(node_map[nodes[k]->prev]) ) +
COMMA;
185 if (links_JSON.size()) {
186 links_JSON = links_JSON.erase(links_JSON.size() - 1);
189 string dl_list_json =
205 virtual void getListElements(vector<
const DLelement<E>*>&
209 unordered_set<const DLelement<E>*> visited;
214 while (it !=
nullptr && visited.emplace(it).second) {
234 for (el = s; el->
getNext() !=
nullptr; el = el->getNext());
250 return this->current != it.current;
310 for (el = s; el->
getNext() !=
nullptr; el = el->getNext());
323 return this->current != it.current;
Definition: DLelement.h:314
iterator & operator--()
Definition: DLelement.h:270
DLelement(const E &val=E(), const string &lab=string())
Definition: DLelement.h:53
iterator & operator++()
Definition: DLelement.h:261
static const string getLinkRepresentation(const LinkVisualizer &lv, const string &src, const string &dest)
Definition: Element.h:273
constexpr int MAX_ELEMENTS_ALLOWED
Definition: DataStructure.h:61
virtual DLelement * getNext() override
Definition: DLelement.h:71
typename DLelement< E >::DLelement_constlisthelper DLelement_ConstList
Definition: DLelement.h:365
iterator end()
Definition: DLelement.h:286
const string COLON
Definition: DataStructure.h:51
iterator & operator++()
Definition: DLelement.h:330
iterator(typename bridges::datastructure::DLelement< E > const *c)
Definition: DLelement.h:318
virtual DLelement * getPrev()
Definition: DLelement.h:102
iterator end()
Definition: DLelement.h:349
E const & getValue() const
Gets the object held in the generic object E.
Definition: Element.h:210
SLelement * next
Definition: SLelement.h:30
virtual void setPrev(DLelement *p)
Definition: DLelement.h:118
these are helper classes for DLelement for easy iteration in a range for loop. It is not meant to be ...
Definition: DLelement.h:224
virtual const string getDStype() const override
Definition: DLelement.h:63
const string OPEN_BOX
Definition: DataStructure.h:54
const string CLOSE_CURLY
Definition: DataStructure.h:53
virtual const DLelement * getPrev() const
Definition: DLelement.h:110
iterator rend()
Definition: DLelement.h:294
DLelement(DLelement *n, DLelement *p=nullptr, const E &val=E(), const string &lab=string())
Definition: DLelement.h:40
these are helper classes for DLelement for easy iteration in a range for loop. It is not meant to be ...
Definition: DLelement.h:302
The singly linked list element, derived from Element.
Definition: SLelement.h:27
E const & operator*() const
Definition: DLelement.h:326
iterator rbegin()
Definition: DLelement.h:353
DLelement_constlisthelper(typename bridges::datastructure::DLelement< E > const *s)
Definition: DLelement.h:306
these methods convert byte arrays in to base64 codes and are used in BRIDGES to represent the color a...
Definition: alltypes.h:4
bool operator!=(const iterator &it) const
Definition: DLelement.h:322
iterator rend()
Definition: DLelement.h:356
iterator rbegin()
Definition: DLelement.h:291
const string CLOSE_BOX
Definition: DataStructure.h:55
void setNext(DLelement *n)
Definition: DLelement.h:89
DLelement_listhelper(typename bridges::datastructure::DLelement< E > *s)
Definition: DLelement.h:228
virtual const DLelement * getNext() const override
Definition: DLelement.h:80
bool operator!=(const iterator &it) const
Definition: DLelement.h:249
E const & operator*() const
Definition: DLelement.h:253
virtual SLelement * getNext()
Returns the next element in the list.
Definition: SLelement.h:75
iterator begin()
Definition: DLelement.h:282
The doubly linked list element, derived from SLelement.
Definition: DLelement.h:24
iterator begin()
Definition: DLelement.h:346
unordered_map< Element *, LinkVisualizer > links
Definition: Element.h:95
const string COMMA
Definition: DataStructure.h:50
const string QUOTE
Definition: DataStructure.h:49
iterator(typename bridges::datastructure::DLelement< E > *c)
Definition: DLelement.h:245
Definition: DLelement.h:239
typename DLelement< E >::DLelement_listhelper DLelement_List
Definition: DLelement.h:363