Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- void insert_at_end();
- struct node{
- int data;
- struct node *link;
- };
- int main()
- {
- struct node *head=malloc(sizeof(struct node));
- struct node *ptr=malloc(sizeof(struct node));
- struct node *pr=malloc(sizeof(struct node));
- head->data=45;
- head->link=ptr;
- ptr->data=50;
- ptr->link=pr;
- pr->data=55;
- pr->link=NULL;
- while(head!=NULL)
- {
- printf("->%d",head->data);
- head=head->link;
- }
- insert_at_end(head,60);
- struct node *ptnr=head;
- while(ptnr!=NULL)
- {
- printf("->%d",ptnr->data);
- ptnr=ptnr->link;
- }
- }
- void insert_at_end(struct node *head, int data)
- {
- struct node *pnt,*temp;
- pnt=head;
- temp->data=60;
- temp->link=NULL;
- while(pnt->link != NULL)
- {
- pnt=pnt->link;
- }
- pnt->link= temp;
- }
Add Comment
Please, Sign In to add comment