Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<stdio.h>
- #include<time.h>
- struct node
- {
- int info;
- struct node *next;
- };
- struct node *head = NULL;
- void add_node(int x)
- {
- struct node *travel = head;
- struct node *temp;
- temp = malloc (sizeof(struct node));
- temp->info = x;
- temp->next=NULL;
- if(head==NULL)
- {
- head = temp;
- }
- else
- {
- while(travel->next!=NULL)
- {
- travel=travel->next;
- }
- travel->next = temp;
- }
- }
- void print()
- {
- struct node* temp= head;
- while(temp!=NULL)
- {
- printf("%d ", temp->info);
- temp=temp->next;
- }
- }
- int main()
- {
- int i, prev=0;
- add_node(5);
- add_node(6);
- print();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement