Program to create and display singly Linked List.

Output:

```100
200
300
```

Output:

```100
200
300
```

Output:

```100
200
300
```

Output:

```100
200
300
```

Explanation

Linked List is a type of data structure in which information is stored in the form of a node which consists of data and address of next node. In a linked list, the node represents a single element.

Pictorial representation of a node:- Representation of a node programmatically:-

 C struct Node { int data; struct Node *next; }; Java class Node { int data; Node next; // Constructor to create a new node // Next is by default initialized as null Node(int d) {data = d;} } Python classNode: # Function to initialize the node object def__init__(self, data): self.data =data # Assign data self.next=None # Initialize # next as null Php class Node { public \$data; public \$next; public function __construct(\$item) { \$this->data = \$item; \$this->next = null; } }

By using the above syntax of creating a node in each language. A linked list is created by creating each node object and giving some value to the data section of the node and linking to the next node by using the next pointer.

Steps to create a linked list by using node:-

1. Firstly we will create an object of the node and initialize them. Each object represents the single node.

 C struct Node* head = NULL; struct Node* second = NULL; head = (struct Node*)malloc(sizeof(struct Node)); second = (struct Node*)malloc(sizeof(struct Node)); third = (struct Node*)malloc(sizeof(struct Node)); Java Node second = new Node(200); Node third = new Node(300); Python second = Node(200) third = Node(300) Php public \$head = null; public \$second=null; public \$third=null; \$this->head = new Node(100); \$this->second=new Node(200); \$this->third=new Node(300);

2. Finally, link nodes to each other. If there is no any next node to link, Next variable of node class will be initialized as null;

 C head->data = 100; //assign data in first node head->next = second; // Link first node with the second node Java list.head.next = second; // Link first node with the second node second.next = third; // Link first node with the second node Python list.head.next = second; # Link first node with second second.next = third; # Link second node with the third node Php \$this->head->next=\$this->second; \$this->second->next=\$this->third;

Next TopicPrograms List    