Advertisement
apl-mhd

Bappy Sir Doubly Linked LIst

Mar 15th, 2017
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.94 KB | None | 0 0
  1. #include <iostream>
  2. #include <cstdio>
  3. using namespace std;
  4.  
  5.  
  6. struct list{
  7.    int data;
  8.    struct list *next;
  9.     struct list *prev;
  10. };
  11.  
  12. typedef struct list node;
  13.  
  14.  
  15. node *insertData(node *head){
  16.  
  17.         node *temp;
  18.  
  19.     for(int i=0; i<5; i++){
  20.         if(head ==NULL){
  21.  
  22.             head = new node();
  23.             head->data = i;
  24.             head->prev=NULL;
  25.             head->next = NULL;
  26.         }
  27.         else{
  28.  
  29.             temp = new node();
  30.  
  31.             temp->data = i;
  32.             temp->next = head;
  33.             head->prev=temp;
  34.             temp->prev = NULL;
  35.             head = temp;
  36.  
  37.  
  38.         }
  39.  
  40.     }
  41.  
  42.    return head;
  43. }
  44.  
  45. void display(node *head){
  46.  
  47.     while(head !=NULL){
  48.  
  49.         printf("%d ", head->data);
  50.  
  51.         head=head->next;
  52.     }
  53.  
  54.  
  55. }
  56.  
  57. int main()
  58. {
  59.     node *head;
  60.  
  61. head = NULL;
  62.  
  63. head = insertData(head);
  64.  
  65. //printf("%d ", head->next->prev->data);
  66.  
  67. display(head);
  68.  
  69.     return 0;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement