sll
unknown
plain_text
2 years ago
820 B
6
Indexable
#include <bits/stdc++.h>
class ListNode
{
int data;
ListNode* next;
public:
ListNode(int d, ListNode* next)
{
this->data = d;
this->next = next;
}
ListNode & get_next()
{
return *(this->next);
}
void setNext(ListNode n)
{
this->next = &n;
}
bool isLast()
{
return !(this->next);
}
};
class SLL
{
ListNode * root;
public:
SLL()
{
root = nullptr;
}
void add_back(ListNode n)
{
if(root == nullptr) root = &n;
else{
ListNode * p = root;
while(p->isLast())
{
p = &(p->get_next());
}
}
}
};
int main()
{
SLL l(5, nullptr);
ListNode el(4, nullptr);
l.setNext(el);
return 0;
}Editor is loading...
Leave a Comment