Professional Documents
Culture Documents
Xii A Linked Lists PDF
Xii A Linked Lists PDF
Linked List is a linear collection of data elements, called nodes pointing to the next nodes by means
of pointers.
Advantages : They overcome the drawbacks of arrays as in linked lists number of elements need not
be predetermined, more memory can be allocated or released during the processing as and when
required, making insertions and deletions much easier and simple.
Avail List : It is a special list which is maintained in the memory consisting of used memory cells from
the heap. The allocation of memory from this list follows the LIFO or last in first out order. Any
memory released with the delete operator is added as a node to the AVAIL list and allocation of new
memory using the new operator results in deletion of a node from the Avail list.
The method of adding free nodes to the avail list is called garbage collection.
Memory Overflow : If no memory is available in heap and the program tries to allocate memory
dynamically using the new operator it is called “memory overflow”
Memory Underflow : If no memory is has been allocated in heap and the program tries to deallocate
memory dynamically using the delete operator it is called “memory underflow”
• Creating / Addition
• Traversal
• Insertion – in sorted / Unsorted List
At the beginning
In the middle
At the end
• Deletion
At the beginning
In the middle
At the end
• Modification
• Searching
• Concatenation of two linked lists
• Splitting of a linked list into two.
• Reversal of a linked list
Stacks : It is a LIFO structure ( Last in First out) i.e. the last element to be inserted is the first to
come out. Stacks can physically be implemented as an array or a linked list. Insertions and deletions
in a stack are both made at the top. Insertion of an element is known as Pushing and deletion is
known as Popping
• Stack as an array
• Stack as a linked list
• Application of Stacks
Reversing a string
Polish Strings
Queue : It is a FIFO structure ( First in First out) i.e. the first element to be inserted is the first to come
out. Queues can physically be implemented as an array or a linked list. Insertions take place at the
end (rear) and deletions in a queue are made in the beginning (front) or at the start.
• Queue as an array
• Queue as a linked list
• Types of Queues
Circular Queues : are queues implemented in a circular form rather than a linear
form. They overcome the problem of unutilised space in linear queues implemented as
arrays.
Deque : (double ended queue) are refined queue in which the elements can be added
or removed at either end but not in the middle.
Input restricted deque : allows insertions at only one end but allows deletions at
both ends of the list.
Output restricted deque : allows deletions at only one end but allows insertions
at both ends of the list.
Assignment
Practical exercises for all the operations on the linked lists would be done.
Questions will be done and discussed from the back of the book.
POINTERS
ASSIGNMENT
1. Differentiate between:
a) Static & Dynamic memory allocation
b) Pointer to an int and pointer to a char
c) Array of pointers and a pointer to an array
d) A pointer to a const and a const pointer
e) int *ptr=new int(5) and int *ptr = new int[5]
3. Why is it faster to use element pointer rather than an index when scanning arrays?
4. Why is an array of characters preferred over two dimensional array of characters ?
Questions given at the back of the chapter would be discussed and given as assigment.