Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct node
- {
- int data;
- struct node*next;
- };
- struct node* head=NULL;
- void insert(int x)
- {
- struct node*temp=(struct node*)malloc(sizeof(struct node*));
- temp->data=x;
- temp->next=NULL;
- if(head==NULL)
- {
- head=temp;
- }
- else
- {
- struct node*temp1=head;
- while(temp1->next!=NULL)
- {
- temp1=temp1->next;
- }
- temp1->next=temp;
- }
- void print()
- {
- struct node*temp=head;
- while(temp!=NULL)
- {
- printf("%d ",temp->data);
- temp=temp->next;
- }
- }
- int main()
- {
- insert(10);
- insert(20);
- insert(30);
- insert(40);
- insert(50);
- print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement