C CODE
C CODE
using std::cout;
using std::endl;
class ListNode {
public:
int val_;
ListNode* next = nullptr;
ListNode* prev = nullptr;
ListNode(int val) {
val_ = val;
}
};
LinkedList() {
// Init the list with a 'dummy' node which makes
// removing a node from the beginning of list easier.
head = new ListNode(-1);
tail = new ListNode(-1);
head->next = tail;
tail->prev = head;
}
head->next->prev = newNode;
head->next = newNode;
}
tail->prev->next = newNode;
tail->prev = newNode;
}
void print() {
ListNode* curr = head->next;
while (curr != tail) {
cout << curr->val_ << " -> ";
curr = curr->next;
}
cout << endl;
}
};