Advertisement
mdnurnobihosen

datastructure13

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