SHARE
TWEET

Untitled

a guest Sep 16th, 2019 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <iostream>
  2. using namespace std;
  3. struct Node{
  4. int data;
  5. struct Node *next;
  6. struct Node *prev;
  7. };
  8. struct Node* head = NULL;
  9. void insert(int new_data) {
  10.     struct Node* new_node = (struct Node*) malloc(sizeof(struct Node));
  11.     new_node->data=new_data;
  12.     new_node->next = head;
  13.     new_node->prev = NULL;
  14.     if(head != NULL)
  15.     head->prev=new_node;
  16.     head = new_node;
  17. }
  18. void display(){
  19.     struct Node* ptr;
  20.     ptr = head;
  21.     while(ptr != NULL){
  22.         cout<<ptr->data <<" ";
  23.         ptr = ptr->next;
  24.     }
  25. }
  26. int main(){
  27. insert(3);
  28. insert(1);
  29. insert(7);
  30. insert(0);
  31. insert(9);
  32. cout<<"The doubly linked list is";
  33. display();
  34. return 0;
  35. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top