Chapter 10 (Linked List,Stack and Queues)
Chapter 10 (Linked List, Stack and Queues)
Linked List –
A linked list is a linear collection of data elements called NODES pointingto the next node by means of pointer. In Linked List, elements called Nodes are createdas and when required, at that memory location which is currently available.In such process memory locations allotted to the nodes may not be contiguous as shown below:12594310678Whereas the memory allocated in case of array is12345678910The Linked lists overcome the drawback of array i.e. you cannot increase the elementsonce defined, and if you need less elements to store ,will results into wastage of space.
Static Memory Allocation – In this memory technique the memory is reserved for thedefined data type and allocated during compile time, before actual processing, thereforenumber of elements to be stores must be predetermined. Arrays are allocated mory usingthis technique.For ex.int a;Dynamic Memory Allocation – The memory technique allocates memory during runtime, as and when required. It also facilitates release of memory, if memory is notrequired any more. Data structures like linked list and trees use this technique for their memory location.
Representation of Linked list in memory
Memory is allocated at run time to the node using new operator. Each node has addressof its node . the last node has NULL pointer in its next part.
Types of Linked List1.Singly Linked List
- All those linked list in which nodes consists of two partsi.e. contents and pointers to next node are called Single Linked List. Thus insingly linked list you traverse in forward direction.
Doubly Linked List –
In this type of lists each node consists of three parts. First part contains theinformation and two pointers in which one pointer points to the previous node an one pointer points to the next node. The traversal is possible in both directions.
3. Circular Linked List –
This is the form of single list, but in this list the last nodecontains the address of first node. Circular queue is implemented with this technique.
Basic Operations on a singly linked list -
Various operations can be performed on listsi.e. searching, Traversal, Insertion, Deletion of node, concatenation, splitting, creation of
1 Ms. Chandni Agarwal