Posts

Showing posts with the label traversing a linked list in java

Singly Linked List Program in Java

What is a Linked List? A Linked List is a linear data structure. It is a collection of nodes such that each node points to the next node. The size of a linked list isn't fixed as the nodes can be added or removed as and when required. The nodes are created by allocating space from the heap memory, using the new keyword. A singly linked list is one in which each node is only capable to point to the next node. A doubly linked list is one in which each node is capable of pointing to the previous as well as the next node. Basic Operations in a Linked List (a) Insertion : We can insert a node in a linked list. A node can be inserted at the beginning, or at the end, or anywhere in-between the list. (b) Deletion : We can delete a node in a linked list. Firstly, we search for the node to be deleted. If found, the deletion takes place and the linked list is readjusted. If not found, then the deletion operation is cancelled. (c) Traversal : We can traverse a linked list, meaning that we can ...