The best way to get a project done faster is to start sooner Tim Highsmith

Singly linked list

Language Java | Level Intermediate | Category Data structure | August 30, 2015 5:23 pm


Data structure Description

Linked list is a data structure consisting of a group of nodes which together represent a sequence. Each node links (memory to next item) to next node. Linked list allocate the memory on demand. Each node contains data and the link to the next node. The last node points to NULL as next link.

Linked list supports insertion, deletion and traversal operations. Insertion and deletion node operations are easily implemented in a linked list. Linked list is useful when the data insert to the list or remove from the list without re-arrange the nodes at any position. The array uses the index to access the elements. If the new element inserted in the middle of the array, the elements need to re-arrange the order. But, the linked list allows to insert in any location using the links.

The dynamic array can be used when the array needs dynamically manage the memory and access the elements using the index. The dynamic array requires more operations to copy old elements to newly created array every time (when the array need more memory). But, the linked list allocate the memory dynamically when the memory requires.

Write a program to implement singly linked list with insert, delete, and traverse operation.


Output

   					 
Items in the linked list:12, 45, 67, 32, 99, 11, 43
Add Items 56 in linked list
Items in the linked list:12, 45, 67, 32, 99, 11, 43, 56
First Item removed in linked list:12
Items in the linked list:45, 67, 32, 99, 11, 43, 56
Last Item removed in linked list:56
Items in the linked list:45, 67, 32, 99, 11, 43

				    

Comments


No comments available!

Please login to add comments.