Page 117 - Computer science 868 Class 12
P. 117
Problem 22:
a. Traversing a Linked List
Step 1: Start.
Step 2: Initialise node ptr = start.
Step 3: Repeat steps 4 and 5 while ptr ! = null.
Step 4: Display ptr → data.
Step 5: Set ptr as ptr → link.
Step 6: Stop.
b. Searching an element in a Linked List
Step 1: Start.
Step 2: Initialise node ptr = start.
Step 3: Repeat steps 4 and 5 while ptr ! = null.
Step 4: If search_value = ptr → data then display ptr → data, go to step 7.
Step 5: Set ptr as ptr → link.
Step 6: if ptr = null then display “value not found”.
Step 7: Stop.
c. Inserting an element at the beginning of a linked list
Step 1: Start.
Step 2: Initialise node ptr and new ptr = start.
Step 3: Set newptr → data = number.
Step 4: Set newptr → link = start.
Step 5: Set start = newptr.
Step 6: Stop.
d. Inserting an element at the end of a linked list
Step 1: Start.
Step 2: Initialise node ptr andnewprt = start.
Step 3: Set newptr → data = number.
Step 4: Set newptr → link = start.
Step 5: Repeat steps 6 whileptr → link ! = null.
Step 6: Set ptr as ptr → link.
Step 7: Set ptr → link = newptr.
Step 8: Stop.
e. Deleting the first node of the linked list
Step 1: Start.
Step 2: Initialise node ptr = start.
Step 3: Set start = start → link.
Step 4: Set ptr → link = null.
Step 5: Stop.
115
Implementation of Algorithms to Solve Problems 115

