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 =
204 virtual void getListElements(vector<
const DLelement<E>*>&
208 unordered_set<const DLelement<E>*> visited;
213 while (it !=
nullptr && visited.emplace(it).second) {
233 for (el = s; el->getNext() !=
nullptr; el = el->getNext());
249 return this->current != it.current;
309 for (el = s; el->getNext() !=
nullptr; el = el->getNext());
322 return this->current != it.current;
Definition: DLelement.h:313
E const & operator*() const
Definition: DLelement.h:325
iterator(typename bridges::datastructure::DLelement< E > const *c)
Definition: DLelement.h:317
iterator & operator++()
Definition: DLelement.h:329
iterator & operator--()
Definition: DLelement.h:333
bool operator!=(const iterator &it) const
Definition: DLelement.h:321
these are helper classes for DLelement for easy iteration in a range for loop. It is not meant to be ...
Definition: DLelement.h:301
iterator rend()
Definition: DLelement.h:355
DLelement_constlisthelper(typename bridges::datastructure::DLelement< E > const *s)
Definition: DLelement.h:305
iterator end()
Definition: DLelement.h:348
iterator rbegin()
Definition: DLelement.h:352
iterator begin()
Definition: DLelement.h:345
Definition: DLelement.h:238
iterator(typename bridges::datastructure::DLelement< E > *c)
Definition: DLelement.h:244
E const & operator*() const
Definition: DLelement.h:252
iterator & operator++()
Definition: DLelement.h:260
bool operator!=(const iterator &it) const
Definition: DLelement.h:248
iterator & operator--()
Definition: DLelement.h:269
these are helper classes for DLelement for easy iteration in a range for loop. It is not meant to be ...
Definition: DLelement.h:223
iterator end()
Definition: DLelement.h:285
iterator begin()
Definition: DLelement.h:281
iterator rbegin()
Definition: DLelement.h:290
iterator rend()
Definition: DLelement.h:293
DLelement_listhelper(typename bridges::datastructure::DLelement< E > *s)
Definition: DLelement.h:227
The doubly linked list element, derived from SLelement.
Definition: DLelement.h:24
virtual DLelement * getPrev()
Definition: DLelement.h:102
virtual DLelement * getNext() override
Definition: DLelement.h:71
virtual const DLelement * getPrev() const
Definition: DLelement.h:110
virtual const string getDStype() const override
Definition: DLelement.h:63
DLelement(DLelement *n, DLelement *p=nullptr, const E &val=E(), const string &lab=string())
Definition: DLelement.h:40
virtual void setPrev(DLelement *p)
Definition: DLelement.h:118
virtual const DLelement * getNext() const override
Definition: DLelement.h:80
void setNext(DLelement *n)
Definition: DLelement.h:89
DLelement(const E &val=E(), const string &lab=string())
Definition: DLelement.h:53
static const string getLinkRepresentation(const LinkVisualizer &lv, const string &src, const string &dest)
Definition: Element.h:310
unordered_map< Element *, LinkVisualizer > links
Definition: Element.h:92
E const & getValue() const
Gets the object held in the generic object E.
Definition: Element.h:207
The singly linked list element, derived from Element.
Definition: SLelement.h:26
virtual SLelement * getNext()
Returns the next element in the list.
Definition: SLelement.h:74
SLelement * next
Definition: SLelement.h:29
constexpr int MAX_ELEMENTS_ALLOWED
Definition: DataStructure.h:62
typename DLelement< E >::DLelement_listhelper DLelement_List
Definition: DLelement.h:362
typename DLelement< E >::DLelement_constlisthelper DLelement_ConstList
Definition: DLelement.h:364
Support for drawing Bar charts.
Definition: alltypes.h:4
const string COLON
Definition: DataStructure.h:52
const string OPEN_BOX
Definition: DataStructure.h:55
const string COMMA
Definition: DataStructure.h:51
const string CLOSE_BOX
Definition: DataStructure.h:56
const string CLOSE_CURLY
Definition: DataStructure.h:54
const string QUOTE
Definition: DataStructure.h:50