fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. struct Node {
  4. int data;
  5. Node* prev;
  6. Node* next;
  7. };
  8. int main() {
  9. Node* head = new Node{10, NULL, NULL};
  10. head->next = new Node{20, head, NULL};
  11. head->next->next = new Node{30, head->next, NULL};
  12. Node* temp = head;
  13. while(temp->next != NULL) {
  14. temp = temp->next;
  15. }
  16. Node* last = new Node{400, temp, NULL};
  17. temp->next = last;
  18.  
  19. temp = head;
  20. while(temp != NULL) {
  21. cout << temp->data << " ";
  22. temp = temp->next;
  23. }
  24.  
  25. return 0;
  26. }
  27.  
Success #stdin #stdout 0.01s 5272KB
stdin
Standard input is empty
stdout
10 20 30 400