data); ptr = ptr -> next; } } int main(){ // node * xyx (xyz is a Pointer variable) struct node * head; struct node * second; struct node * third; struct node * fourth; //allocate memory for nodes in HEAP head = (struct node *) malloc(sizeof(struct node)); second = (struct node *) malloc(sizeof(struct node)); third = (struct node *) malloc(sizeof(struct node)); fourth = (struct node *) malloc(sizeof(struct node)); //link nodes '->' arrow operator head -> data = 7; head -> next = second; second -> data = 11; second -> next = third; third -> data = 15; third -> next = fourth; //this is how to take input for a linked list node printf("Enter the elemen"> data); ptr = ptr -> next; } } int main(){ // node * xyx (xyz is a Pointer variable) struct node * head; struct node * second; struct node * third; struct node * fourth; //allocate memory for nodes in HEAP head = (struct node *) malloc(sizeof(struct node)); second = (struct node *) malloc(sizeof(struct node)); third = (struct node *) malloc(sizeof(struct node)); fourth = (struct node *) malloc(sizeof(struct node)); //link nodes '->' arrow operator head -> data = 7; head -> next = second; second -> data = 11; second -> next = third; third -> data = 15; third -> next = fourth; //this is how to take input for a linked list node printf("Enter the elemen"> data); ptr = ptr -> next; } } int main(){ // node * xyx (xyz is a Pointer variable) struct node * head; struct node * second; struct node * third; struct node * fourth; //allocate memory for nodes in HEAP head = (struct node *) malloc(sizeof(struct node)); second = (struct node *) malloc(sizeof(struct node)); third = (struct node *) malloc(sizeof(struct node)); fourth = (struct node *) malloc(sizeof(struct node)); //link nodes '->' arrow operator head -> data = 7; head -> next = second; second -> data = 11; second -> next = third; third -> data = 15; third -> next = fourth; //this is how to take input for a linked list node printf("Enter the elemen">
//Traversal in Linked List : Reading and printing the elements via a pointer variable

#include<stdio.h>
#include<stdlib.h>

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

void linkedlistTraversal(struct node *ptr){
	while (ptr != NULL){
		//prints the element of the linked lists
		printf("Element: %d \\n", ptr -> data);
		ptr = ptr -> next;
	}
}

int main(){
	// node * xyx (xyz is a Pointer variable)
	struct node * head;
	struct node * second;
	struct node * third;
	struct node * fourth;

	//allocate memory for nodes in HEAP

	head = (struct node *) malloc(sizeof(struct node));
	second = (struct node *) malloc(sizeof(struct node));
	third = (struct node *) malloc(sizeof(struct node));
	fourth = (struct node *) malloc(sizeof(struct node));

	//link nodes '->' arrow operator

	head -> data = 7;
	head -> next = second;
	second -> data = 11;
	second -> next = third;
	third -> data = 15;
	third -> next = fourth;
	//this is how to take input for a linked list node
	printf("Enter the element for 4th node : ");
	scanf("%d", &fourth -> data);
	fourth -> next = NULL;
	linkedlistTraversal(head);
return 0;
}