Untitled

mail@pastecode.io avatar
unknown
plain_text
2 years ago
677 B
4
Indexable
#include <stdio.h>
#include <stdlib.h>

struct node{
    
    int data;
    struct node *next;
    
    
    
};

void printList(struct node* n)
{
    while (n != NULL) {
        printf(" %d ", n->data);
         n -> next;
    }
};

int main()
{
    struct node* head =NULL;
    struct node* second =NULL;
    struct node* third =NULL;
    
    head = malloc(sizeof(struct node ));
    second = malloc(sizeof(struct node));
    third = malloc(sizeof(struct node));


    head -> data = 1;
    head -> next = second;
    
    second -> data = 2;
    second -> next = third;
    
    third -> data = 3;
    third -> next = NULL;
    
    
    printList(head);


    return 0;
}