Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- typedef struct NODE
- {
- int data;
- struct NODE *next;
- } node;
- node *head;
- void insert(int data)
- {
- node *newnode;
- newnode=(node*)malloc(sizeof(node));
- newnode->data=data;
- newnode->next=NULL;
- node *current=head;
- while(current->data!=10){
- current=current->next;
- }
- newnode->next=current->next;
- current->next=newnode;
- }
- void print()
- {
- node *current=head;
- while(current!=NULL){
- printf("%d ", current->data);
- current=current->next;
- }
- }
- int main()
- {
- head=(node *)malloc(sizeof(node));
- head->data=3;
- head->next=(node *)malloc(sizeof(node));
- head->next->data=10;
- head->next->next=(node *)malloc(sizeof(node));
- head->next->next->data=2;
- head->next->next->next=(node *)malloc(sizeof(node));
- head->next->next->next->data=1;
- head->next->next->next->next=NULL;
- insert(15);
- print();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment