Traversal in singly linked list Dsa
#include <stdio.h>
#include<stdlib.h>
struct node {
int data;
struct node *next;
};
void linkedlistTraversal(struct node *ptr){
while(ptr != NULL){
printf("Element %d\n",ptr -> data);
ptr = ptr -> next;
}
}
int main(){
struct node *head=(struct node *)malloc(sizeof(struct node));
struct node *second=(struct node *)malloc(sizeof(struct node));
struct node *third=(struct node *)malloc(sizeof(struct node));
head -> data = 45;
head -> next = second;
second -> data = 32;
second -> next = third;
third -> data = 87;
third -> next = NULL;
linkedlistTraversal(head);
return 0;
}