Page 115 - Computer science 868 Class 12
P. 115
Step 9: If ch is equal to space then go to Step 10 else go to Step 13.
Step 10: If word = del_word then go to Step 12.
Step 11: Add word to new_sentence and then add space to new_sentence. Go to Step 14
Step 12: Initialise word to null, go to Step 14.
Step 13: Add ch to word.
Step 14: Increment i by 1.
Step 15: Display new_sentence.
Step 16: Stop.
3.5.7 Recursive Algorithms
b
Problem 18: Write a recursive algorithm to find power(a, b) or a .
Step 1: Start.
Step 2: Accept a and b.
Step 3: If b = 1 then return 1, else go to Step 3.
Step 4: Return a x power(a, b-1).
Step 5: Stop.
Problem 19: Write a recursive algorithm to find the sum of the digits of a number sumofdigit(num).
Step 1: Start.
Step 2: If num = 0 then return 0, else go to Step 3.
Step 3: Return num % 10 + sumofdigit(num/10).
Step 4: Stop.
3.5.8 Algorithms on Operations in STACK
Stack is a data structure that follows LIFO (Last in first out principle).
Note: Stack is covered in detail in later part of this book.
Problem 20:
a. Pushing data into stack assuming top = -1
Step 1: Start.
Step 2: If top = size then print “Stack full .. overflow”, and go to step 5.
Step 3: Increment top by 1.
Step 4: Set array[top] = x.
Step 5: Stop.
b. Popping data from stack
Step 1: Start.
Step 2: If top = -1 then return -999.
Step 3: Store value = array[top].
Step 4: Decrease top by 1.
113
Implementation of Algorithms to Solve Problems 113

