You are on page 1of 75

CIRCULAR LINKED LIST

Drawbacks of singly linked list

❏ Not possible to access predecessor node.


❏ External pointer must always be at the first node to traverse the
list.
Circular Linked List

START
5 17 2

A linked list where the last node contains the address of first node.

No null links.
Operations on CLL

➔ Traversing

➔ Insertion

➔ Deletion

➔ Searching

➔ Concatenation
Traversing
TEMP

START 5 17 2

Algorithm: Traversing(START)
5 17 2
1. Set TEMP=START
2. Repeat steps 3 & 4 while (LINK[TEMP] != START)
3. Process INFO[TEMP]
4. Set TEMP = LINK[TEMP]
5. Process INFO[TEMP]
6. EXIT
Insertion at beginning
START

5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
Insertion at beginning
NEW START

5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
Insertion at beginning
NEW START

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5.
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
8. Set LINK[NEW] = START
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
8. Set LINK[NEW] = START
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
8. Set LINK[NEW] = START
9. Set START = NEW
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
8. Set LINK[NEW] = START
9. Set START = NEW
Insertion at beginning
NEW START TEMP

48 5 17 2

Algorithm: INSERT_BEG (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
8. Set LINK[NEW] = START
9. Set START = NEW
10. EXIT
Insertion at end
START

5 17 2

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3.
Insertion at end
START
NEW

5 17 2

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
Insertion at end
START
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
Insertion at end
START
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7.
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7.
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7.
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
8. Set LINK[NEW] = START
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
8. Set LINK[NEW] = START
Insertion at end
START TEMP
NEW

5 17 2 45

Algorithm: INSERT_END (START, ITEM, AVAIL)

1. If (AVAIL = NULL ) then PRINT”Overflow” & EXIT


2. Set NEW = AVAIL & AVAIL = LINK[AVAIL]
3. Set INFO[NEW] = ITEM
4. Set TEMP = START
5. Repeat step 6 while ( LINK[TEMP] != START)
6. Set TEMP = LINK[TEMP]
7. Set LINK[TEMP] = NEW
8. Set LINK[NEW] = START
9. EXIT
Deletion at Beginning
START

5 17 2

Algorithm : Delete_beg ( START, AVAIL)


Deletion at Beginning
START

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5.
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5.
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5. Set LINK[TEMP = LINK[START]
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5. Set LINK[TEMP = LINK[START]
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5. Set LINK[TEMP = LINK[START]
6. Set TEMP = START
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5. Set LINK[TEMP = LINK[START]
6. Set TEMP = START
Deletion at Beginning
START TEMP

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5. Set LINK[TEMP = LINK[START]
6. Set TEMP = START
7. Set START = LINK[START]
Deletion at Beginning
TEMP START

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5. Set LINK[TEMP = LINK[START]
6. Set TEMP = START
7. Set START = LINK[START]
Deletion at Beginning
TEMP START

5 17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5. Set LINK[TEMP = LINK[START]
6. Set TEMP = START
7. Set START = LINK[START]
8. Set LINK [TEMP] = AVAIL & AVAIL = TEMP
9. EXIT
Deletion at Beginning
START

17 2

Algorithm : Delete_beg ( START, AVAIL)

1. If (START= NULL) then PRINT”Underflow” &EXIT


2. Set TEMP = START
3. Repeat step 4 while (LINK[TEMP] != START)
4. TEMP = LINK[TEMP]
5. Set LINK[TEMP = LINK[START]
6. Set TEMP = START
7. Set START = LINK[START]
8. Set LINK [TEMP] = AVAIL & AVAIL = TEMP
9. EXIT
Deletion at end
START

5 17 2

Algorithm: Delete_end ( START, AVAIL)


Deletion at end
START

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


Deletion at end
START

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
Deletion at end
START TEMP
PRED= NULL

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
Deletion at end
START TEMP
PRED= NULL

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
3. Repeat Step 4 while (LINK[TEMP] != START)
4. Set PRED = TEMP & TEMP = LINK[TEMP]
Deletion at end
START PRED TEMP

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
3. Repeat Step 4 while (LINK[TEMP] != START)
4. Set PRED = TEMP & TEMP = LINK[TEMP]
Deletion at end
START PRED TEMP

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
3. Repeat Step 4 while (LINK[TEMP] != START)
4. Set PRED = TEMP & TEMP = LINK[TEMP]
Deletion at end
START PRED TEMP

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
3. Repeat Step 4 while (LINK[TEMP] != START)
4. Set PRED = TEMP & TEMP = LINK[TEMP]
5. Set LINK[PRED] = START
Deletion at end
START PRED TEMP

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
3. Repeat Step 4 while (LINK[TEMP] != START)
4. Set PRED = TEMP & TEMP = LINK[TEMP]
5. Set LINK[PRED] = START
Deletion at end
START PRED TEMP

5 17 2

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
3. Repeat Step 4 while (LINK[TEMP] != START)
4. Set PRED = TEMP & TEMP = LINK[TEMP]
5. Set LINK[PRED] = START
6. Set LINK[TEMP] = AVAIL & AVAIL = TEMP
Deletion at end
START PRED

5 17

Algorithm: Delete_end ( START, AVAIL)

1. If (START=NULL) then PRINT” Underflow” & EXIT


2. Set PRED= NULL & TEMP = START
3. Repeat Step 4 while (LINK[TEMP] != START)
4. Set PRED = TEMP & TEMP = LINK[TEMP]
5. Set LINK[PRED] = START
6. Set LINK[TEMP] = AVAIL & AVAIL = TEMP
7. EXIT
Searching
TEMP

START 5 17 2

Algorithm: Searching(START, ITEM)

1. Set TEMP=START 12
2. Repeat steps 3 & 4 while( (LINK[TEMP] != START)
3. If (ITEM = INFO[TEMP]) then Print” FOUND” & EXIT
4. Set TEMP = LINK[TEMP]
5. If ( LINK[TEMP]= START) then
If(ITEM=INFO[TEMP]) then Print “ ITEM FOUND” & EXIT

6. Print “ ITem NOT FOUND”


7. EXIT
Concatenation of Circular LLs
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)


Concatenation of Circular LLs
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
6. Repeat step 7 while( LINK[TEMP] != START2)
7. Set TEMP = LINK[TEMP]
8.
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
6. Repeat step 7 while( LINK[TEMP] != START2)
7. Set TEMP = LINK[TEMP]
8.
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
6. Repeat step 7 while( LINK[TEMP] != START2)
7. Set TEMP = LINK[TEMP]
8. Set LINK[TEMP] = START1
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)

1. Set TEMP = START1


2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
6. Repeat step 7 while( LINK[TEMP] != START2)
7. Set TEMP = LINK[TEMP]
8. Set LINK[TEMP] = START1
Concatenation of Circular LLs
TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)


1. Set TEMP = START1
2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
6. Repeat step 7 while( LINK[TEMP] != START2)
7. Set TEMP = LINK[TEMP]
8. Set LINK[TEMP] = START1
9. Set START3 = START1
Concatenation of Circular LLs
START 3 TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)


1. Set TEMP = START1
2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
6. Repeat step 7 while( LINK[TEMP] != START2)
7. Set TEMP = LINK[TEMP]
8. Set LINK[TEMP] = START1
9. Set START3 = START1
Concatenation of Circular LLs
START 3 TEMP
START 2

START 1
5 17 2 5 17

Algorithm: Concatenation (START1, START2, START3)


1. Set TEMP = START1
2. Repeat step 3 while( LINK[TEMP] != START1)
3. Set TEMP = LINK[TEMP]
4. Set LINK[TEMP] = START2
5. Set TEMP = START2
6. Repeat step 7 while( LINK[TEMP] != START2)
7. Set TEMP = LINK[TEMP]
8. Set LINK[TEMP] = START1
9. Set START3 = START1
10. EXIT

You might also like