Quick actions

cmd+k|ctrl+k

Navigation

Languages

traversing a linked list

Snippet info

Language

C

Visibility

public

Author

ganesh26

Created

2020-07-02T13:29:56Z

Updated

2020-07-02T13:29:56Z

#include <stdio.h>
struct Node
{ 
    int data;
    struct Node* next;
};

void printlist(struct Node* temp)
{
    printf("Linked list is \n ");
    while(temp != NULL)
    {
        printf("%d ", temp->data);
        temp = temp->next;
    }
}
int main(void) {
    printf("Hello World!\n");
    
    struct Node * head = NULL;
    struct Node * second = NULL;
    struct Node* third = NULL;
    head = (struct Node*)malloc(sizeof(struct Node));
     second = (struct Node*)malloc(sizeof(struct Node));
      third = (struct Node*)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;
}
INFO