0% found this document useful (0 votes)
14 views40 pages

Linked List

Uploaded by

Raghu M E
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views40 pages

Linked List

Uploaded by

Raghu M E
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 40

Linked List

Introduction

Linked-List basic concepts

Linked List Implementation.

Types of Linked List

Circular Linked List

Doubly Linked List


Arrays:

Limitation associated with arrays.

Fixed space at the time of declaration.

If more space required at the time of execution, then enhance is not possible.
Linked list

Dynamic memory allocation is possible.

LL is o collection of nodes or data elements logically connected/related to each other.

When new elements need to be added then nodes are created and appended to LL.

In LL each element point to next element in the list.

Each elements are referred as nodes. Each node as two parts Data field and link field. Called INFO and NEXT.

Next part of last node is NULL.

INFO NEXT
Node representation.
Advantages of LL

1. Allows dynamic memory allocation.

2. Efficient utilization of memory space. – only required memory space is reserved.

3. Easy to insert and delete nodes – no shifting is required


Dis-advantages

1. Requires more memory space (when compared with arrays).

2. Accessing elements is more difficult.- traversing required because no index to linked list.
Linked List Implementation.

Two tasks

1. Declaring the list node.

2. Defining the LL operation.

Declaring the Linked List node

struct node
{
int INFO;
struct node *NEXT;
};
typedef struct node NODE;

Sele referential structure


Linked List Operation

Different operation on linked list are

1. Insert

2. Delete

3. Search

4. Print.
Insert Operation
Insert (value)

Step 1: start
Step 2: set PTR= addressof (newnode) /* Allocate a new node and assign its address to PTR*/

Step 3: set PTR->INFO=value;


Step 4: if FIRST=NULL then goto step 5 else step 7
Step 5: set FIRST=PTR and LAST=PTR
Step 6: set PTR->NEXT=NULL and goto step 8;
Step 7:set LAST->NEXT=PTR, PTR->NEXT=NULL and LAST=PTR;
Step 8: STOP;
Delete

Removal of existing element from the list.

a. Location of the element is identified.


b. The element value is retrieved.
c. Link pointer of preceding node is reset.

3 possible deletion

1. Deletion from the beginning.


2. Deletion from the end
3. Deletion from somewhere in the middle.
delete(value)

Step 1: start
Step
2: set LOC=search(value) /* Allocate a new node and assign its address to PTR*/
Step 3: If LOC=NULL goto step 4 else step 5;
Step 4: return and print “deletion unsuccessful” and stop.
Step 5: if LOC=FIRST then goto step 6 else step 10
Step 6: if FIRST=LAST then goto step 7 else step 8;
Step 7:set FIRST=LAST=NULL and goto step 9;
Step 8: FIRST=FIRST->NEXT;
Step 9: return “Deletion is successful” and stop.
Step 10: set TEMP=LOC-1;
Step 11: set TEMP->NEXT=LOC->NEXT;
Step 12: if LOC=LAST goto step 13 else step 14.
Step 13: set LAST=TEMP.
Step 14: return “deletion is successful”
Step 15: STOP
Search

Finding element in the list or not.

3 steps

1. Travers the list sequentially starting from the FIRST node.

2. Return the location of searched node as soon as found.

3. Return the search failure notification if entire list is traversed without any match.
search(value)
Step 1: start
Step 2: If FIRST=NULL goto step 3 else step 4.
Step 3: return “search unsuccessful, element not found” and stop;
Step 4: set PTR=FIRST;
Step 5: Repeat step 6-8 until PTR!=LAST;
Step 6: If PTR->INFO=value goto step 7 else goto step 8;
Step 7: Return “Search is Successful “, PTR and stop;
Step 8: set PTR=PTR->NEXT;
Step 9: If LAST->INFO=value goto step 10 else step 11.
Step 10: Return “Search is Successful “, LAST and stop.
Step 11: return “search unsuccessful, element not found” and stop.
Step 12: STOP;
Print
Display the list contents.
Print()
Step 1: start
Step 2: if FIRST=NULL goto step 3 else step 4
Step 3: Display “Empty list” and stop;
Step 4: if FIRST=LAST then goto step 5 else goto step 6
Step 5: Display (FIRST->INFO) and stop
Step 6: set PTR=FIRST.
Step 7: Repeat setp 8-9 UNTIL PTR!=LAST;
Step 8: Display (PTR->INFO);
Step 9: PTR=PTR->NEXT.
Step 10: Display (LAST->INFO).
Step 11: STOP.
Types of LL

1. Single LL.

2. Circular LL

3. Doubly LL.
Doubly Linked List

LAST
Operation on DLL

Insert

Delete

Search

Print
Linked list implementation of Stack

PUSH

POP

Display
Priority Queue

You might also like