Advertisement
mdnurnobihosen

datastructure12

Jun 21st, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.81 KB | None | 0 0
  1. ///Home Work 12 @Nurnobi shanto
  2. #include<stdio.h>
  3. #include<stdlib.h>
  4.  
  5. typedef struct Node{
  6.     char data[30];
  7.     struct Node *ptr;
  8. }node;
  9. node *head = NULL;
  10.  
  11.  
  12. int main(){
  13.     printf("Enter Data to store:\n");
  14.     node *n1;
  15.     n1 = (node*)malloc(sizeof(node));
  16.     scanf("%s", &n1-> data);
  17.     n1-> ptr = NULL;
  18.     head = n1;
  19.  
  20.     node *n2;
  21.     n2 = (node*)malloc(sizeof(node));
  22.     scanf("%s", &n2->data);
  23.     n2-> ptr = NULL;
  24.     n1-> ptr = n2;
  25.  
  26.     node *n3;
  27.     n3 = (node*)malloc(sizeof(node));
  28.     scanf("%s", &n3->data);
  29.     n3->ptr = NULL;
  30.     n2-> ptr = n3;
  31.  
  32.  
  33.     node *temp = head;
  34.     int c = 0;
  35.     while(temp != NULL){
  36.         printf("Stored Data: %s\n", temp-> data);
  37.         temp = temp-> ptr;
  38.         c++;
  39.     }
  40.     printf("\nTotal node: %d\n", c);
  41.  
  42.     return 0;
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement