Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct linklist
- {
- int data;
- struct linklist *next;
- } node;
- void newjoin (node *t, int data)
- {
- while (t->next != NULL)
- {
- t = t->next;
- }
- t->next = (node*)malloc(sizeof(node));
- t->next->data = data;
- t->next->next = NULL;
- }
- void display(node *t)
- {
- while (t!= NULL)
- {
- printf("%d ", t->data);
- t = t->next;
- }
- }
- void insert_after(node *t, int x,int data)
- {
- int count=0;
- while(t!= NULL)
- {
- count++;
- if(count==x)
- break;
- t = t->next;
- }
- node *tmp=t->next;
- t->next = (node*)malloc(sizeof(node));
- t->next->data = t->data;
- t->next->next = tmp;
- t->data=data;
- }
- int main()
- {
- int data, i;
- node *tab = (node*)malloc(sizeof(node));
- tab->next = NULL;
- printf(" Input five elements here\n");
- for(i=0; i<5; i++)
- {
- printf("Input data for your node %d: ",i+1);
- scanf("%d", &data);
- newjoin(tab,data);
- }
- printf("\nThe elements are - ");
- display(tab);
- int nth;
- printf("\nInsert 95 at which position: ");
- scanf("%d", &nth);
- insert_after(tab,nth,95);
- // for(i=1; i<6; i++)
- // {
- // printf("DEEP\n");
- // }
- display(tab);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement