Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- struct Node{
- int x;
- struct Node *next;
- };
- void display(struct Node *head){
- while(head!=NULL){
- printf("%d \n", head->x);
- head=head->next;
- }
- }
- int main(){
- struct Node *head;
- head = malloc(sizeof(struct Node));
- struct Node *tail;
- tail=head;
- for(int i=-20;i<21;i=i+5){
- struct Node *tmp;
- tmp=malloc(sizeof(struct Node));
- tmp->x = i;
- tail->next=tmp;
- tmp->next=NULL;
- tail=tmp;
- }
- display(head);
- while(head!=NULL){
- struct Node *tmp = head;
- tmp=head->next;
- free(head);
- head=tmp;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement