Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<stdlib.h>
- struct mylist
- {
- int data ;
- struct mylist*next;
- };
- struct mylist*head=NULL;
- void display()
- {
- struct mylist*temp=head;
- while (temp!=NULL)
- {
- printf("%d->",temp->data);
- temp=temp->next;
- }
- printf("\n");
- }
- void insert_first(int data)
- {
- struct mylist*temp=(struct mylist*)malloc(sizeof(struct mylist));
- temp->data=data;
- temp->next=head;
- head=temp;
- }
- void insert_last(int data)
- {
- struct mylist*temp=head;
- struct mylist*new_node=(struct mylist*)malloc(sizeof(struct mylist));
- new_node->data=data;
- new_node->next=NULL;
- if (temp==NULL)
- {
- head=new_node;
- return;
- }
- while(temp->next!=NULL)
- {
- temp=temp->next;
- }
- temp->next=new_node;
- return;
- }
- void creat(int data)
- {
- insert_last(data);
- }
- int main()
- {
- insert_last(5);
- insert_last(10);
- display();
- return 0;
- }
- +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement