Advertisement
Guest User

new

a guest
Dec 7th, 2019
233
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.49 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <malloc.h>
  4. struct node
  5. {
  6.     int data;
  7.     struct node *next;
  8. };
  9. struct node *create(int data)
  10. {
  11.     struct node *t = (struct node *)malloc(sizeof(struct node));
  12.     t->data = data;
  13.     t->next = NULL;
  14.     return t;
  15. }
  16. struct node *ll()
  17. {
  18.     int t, n, counter = 0;
  19.     struct node *head;
  20.     struct node *temp;
  21.     printf("enter no of elements\n");
  22.     scanf("%d", &n);
  23.     printf("enter the elemenst");
  24.     while (counter < n)
  25.     {
  26.         scanf("%d", &t);
  27.         if (counter == 0)
  28.         {
  29.             head = create(t);
  30.             temp = head;
  31.             counter++;
  32.             continue;
  33.         }
  34.         while (temp->next != NULL)
  35.         {
  36.             temp = temp->next;
  37.         }
  38.         temp = create(t);
  39.         counter++;
  40.     }
  41.     return head;
  42. }
  43. void display(struct node *temp)
  44. {
  45.     printf("elements");
  46.     printf("%d", temp->data);
  47.     while (temp->next != NULL)
  48.     {
  49.         printf("%d", temp->data);
  50.         temp = temp->next;
  51.     }
  52. }
  53. struct node *merge(struct node *x, struct node *y)
  54. {
  55.     struct node *head;
  56.     struct node *temp1 = x;
  57.     struct node *temp2 = y;
  58.     struct node *temp = x;
  59.     head = x;
  60.     for (; temp1->next != NULL && temp2->next != NULL; temp = temp->next, temp1 = temp1->next, temp2 = temp2->next)
  61.     {
  62.         temp->next = temp1;
  63.         temp = temp->next;
  64.         temp->next = temp2;
  65.     }
  66.     if (temp1->next == NULL)
  67.     {
  68.         while (temp2->next != NULL)
  69.         {
  70.             temp = temp2;
  71.             temp2 = temp2->next;
  72.         }
  73.     }
  74.     else
  75.     {
  76.         while (temp1->next != NULL)
  77.         {
  78.             temp = temp1;
  79.             temp1 = temp1->next;
  80.         }
  81.     }
  82.     return head;
  83. }
  84. int main()
  85. {
  86.     struct node *h1;
  87.     struct node *h2;
  88.     struct node *h;
  89.     h1 = ll();
  90.     printf("%d", h1->next->next->data);
  91.     display(h1);
  92.  
  93.     return 0;
  94. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement