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