Upcoming SlideShare
×

1,538 views

Published on

0 Likes
Statistics
Notes
• Full Name
Comment goes here.

Are you sure you want to Yes No
Your message goes here
• Be the first to comment

• Be the first to like this

Views
Total views
1,538
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
75
0
Likes
0
Embeds 0
No embeds

No notes for slide

1. 1. PRESENTAION ON LINKED LIST
2. 2. LINKED LIST DEFINITION ARRAY Vs LINKED LIST TYPES OPERATIONS
3. 3. Introduction Linear data structure Dynamic data structure A linked list is a series of connected nodes Each node contains at least ◦ A piece of data (any type) ◦ Pointer to the next node in the list NODE : Info link Data Pointer item
4. 4. REPRESENTATION OF A LINKED LIST WITH 3 NODESStart Data item Data item Data item X Head: pointer to the first node The last node points to NULL
5. 5. REPRESENTATION OF ANEMPTY LINKED LIST START X
7. 7. Variations of Linked Lists header linked lists ◦ A linked list with a special node called header node in the beginning of the list A B C X Head header node ◦ Header node doesn’t contain the actual data.
8. 8. Variations of Linked Lists Circular linked lists ◦ The last node points to the first node of the list A B C Head ◦ How do we know when we have finished traversing the list? (Tip: check if the pointer of the current node is equal to the head.)
9. 9. Variations of Linked Lists Doubly linked lists ◦ Each node points to not only successor but the predecessor ◦ There are two NULL: at the first and last nodes in the list ◦ Advantage: given a node, it is easy to visit its predecessor. Convenient to traverse lists backwards A B C Back info forw Head Tail
10. 10. Operations on singly linkedlist  Creation Traversing(visiting) Counting Insertion Deletion Searching Merging(concatenating two lists) Reversing the list Updating Copying
11. 11. Algorithm to traverse and countone-way listSet PTR=HEAD.Set count =0.Repeat step while PTR!=NULL• Apply process to INFO[PTR].• Set COUNT=COUNT+1• Set PTR=LINK[PTR].Write : COUNTEXIT
12. 12. Algorithm to search an elementITEM in an unsorted one-waylist HEAD=NULL, thenSet• Write: “list is empty”• Set LOC= NULL• And exitSet PTR=HEADRepeat while PTR=!NULL • If ITEM=INFO[PTR] • Set LOC=PTR • And exit • Else • Set PTR=LINK[PTR]
13. 13. Set LOC= NULLWrite:”search is unsuccessful”Exit
14. 14. Algorithm to search an elementITEM in an unsorted one-way listSet HEAD=NULL, then • Write: “list is empty” • Set LOC= NULL • And exitSet PTR=HEADRepeat while PTR=!NULL • If ITEM=INFO[PTR] • Set LOC=PTR • Write:”search is successful” • And exit • Else if ITEM>INFO[PTR] • Set PTR=LINK[PTR] • Else[ITEM<INFO[PTR]] • Set LOC=NULL • Write:”search is unsuccessful” • And exit
15. 15. Set LOC= NULLWrite:”search is unsuccessful”Exit
16. 16. Algorithm to insert an elementITEM at the begnning one-waylistIf AVAIL=NULL, then• Write:”overflow”• And exitSet NEW=AVAIL• Set AVAIL=LINK[AVAIL]Set INFO[NEW]=ITEMSet LINK[NEW]=HEAD• Set HEAD= NEWEXIT
17. 17. Algorithm to insert an node aftera node with location LOC inone-way listIf AVAIL=NULL, then• Write:”overflow”• And exitSet NEW=AVAIL• Set AVAIL=LINK[AVAIL]Set INFO[NEW]=ITEMIf LOC =NULL, then• Set LINK[NEW]=HEAD• Set HEAD =NEW