Double Linked List with Smart Pointers
Reimplement Double Linked List With Smart Pointers
class Node{
public:
int data;
Node(int data){
this->data = data;
}
public:
shared_ptr<Node> prev;
shared_ptr<Node> next;
};

public:
shared_ptr<Node> tail;
public:

void fun(){
printf("fun()\n");
}

void append(shared_ptr<Node> node){
}else{
tail->next = node;
node->prev = tail;
tail = node;
}
}

friend std::ostream& operator<<(std::ostream& out, shared_ptr<LinkedList> list){
while(curr){
out<<'['<<curr->data<<']'<<'\n';
curr = curr->next;
}
return out;
}

void print(){
while(curr){
printf("[%d]\n", curr->data);
curr = curr->next;
}
}
bool remove(shared_ptr<Node> node){
bool ret = false;
if(node && curr){
while(curr){
if(curr == node){
if(curr->prev == nullptr){
if(curr->next == nullptr){
// [curr]
node.reset();
tail.reset();
}else{
// [curr]->[]
shared_ptr<Node> next = curr->next;
curr->next.reset();
next->prev.reset();
}
}else{
if(curr->next == nullptr){
// []->[curr]
shared_ptr<Node> prev = curr->prev;
curr->prev.reset();
prev->next.reset();
tail = prev;
}else{
// []->[curr]->[]
shared_ptr<Node> next = curr->next;
shared_ptr<Node> prev = curr->prev;
next->prev = prev;
prev->next = next;
}
}
ret = true;
}
curr = curr->next;
}
}
return ret;
}
};