Thursday, December 6, 2007

Linked Lists

Linked list: -
Linked list is a linear data structure that works on a principle Random in Random out (RIRO). Linked list can be defined as Collection of logically adjacent nodes in which logical adjacency is maintained by pointers.
Ex: The days of the week (Sun, Mon, Tue, Wed, Thu, Fri, Sat)
Linked lists can be represented in memory by two ways they are
· Using array method 2. Using pointer method


Array method :
In array method all the elements are stored in the continuous memory locations. It is having following disadvantages they are
1. It follows static memory allocation.
2. It is not possible to extend the size of the array at runtime
3. Due to static memory allocation some memory space will be wasted.
Pointer method :
In pointer method all the data elements are represented using nodes. Each node is having data item and pointer to the next node. The elements in the list need not occupy continuous memory locations. The advantages of this method are
· Efficient memory management is possible, i.e., due to dynamic memory allocation the memory is not wasted
· It is possible to add or delete an element any ware in the list
· It is dynamic in nature
· It is possible to handle a list of any size
· It is possible to extend the size of a list at runtime

Various operations performed on lists: -
The operations performed on lists are.
1. Inserting a new element at the given position.
2. Delete the element from the given position
3. Find the length of the list
4. Read the list from left to right
5. Retrieve the ith element
6. Copy a list
7. Sort the elements in either ascending or descending order
8. Combine 2 or more list

0 Comments:

 
^ Scroll to Top