Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <conio.h>
- #include <malloc.h>
- struct node
- {
- int data;
- struct node *next;
- };
- struct node *create(int data)
- {
- struct node *t = (struct node *)malloc(sizeof(struct node));
- t->data = data;
- t->next = NULL;
- return t;
- }
- struct node *ll()
- {
- int t, n, counter = 0;
- struct node *head;
- struct node *temp;
- printf("enter no of elements\n");
- scanf("%d", &n);
- printf("enter the elemenst");
- while (counter < n)
- {
- scanf("%d", &t);
- if (counter == 0)
- {
- head = create(t);
- temp = head;
- counter++;
- continue;
- }
- while (temp->next != NULL)
- {
- temp = temp->next;
- }
- temp = create(t);
- counter++;
- }
- return head;
- }
- void display(struct node *temp)
- {
- printf("elements");
- printf("%d", temp->data);
- while (temp->next != NULL)
- {
- printf("%d", temp->data);
- temp = temp->next;
- }
- }
- struct node *merge(struct node *x, struct node *y)
- {
- struct node *head;
- struct node *temp1 = x;
- struct node *temp2 = y;
- struct node *temp = x;
- head = x;
- for (; temp1->next != NULL && temp2->next != NULL; temp = temp->next, temp1 = temp1->next, temp2 = temp2->next)
- {
- temp->next = temp1;
- temp = temp->next;
- temp->next = temp2;
- }
- if (temp1->next == NULL)
- {
- while (temp2->next != NULL)
- {
- temp = temp2;
- temp2 = temp2->next;
- }
- }
- else
- {
- while (temp1->next != NULL)
- {
- temp = temp1;
- temp1 = temp1->next;
- }
- }
- return head;
- }
- int main()
- {
- struct node *h1;
- struct node *h2;
- struct node *h;
- h1 = ll();
- printf("%d", h1->next->next->data);
- display(h1);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement