Академический Документы
Профессиональный Документы
Культура Документы
com
Pseudo Codes
Program Number 14
Write a recursive C program for searching an element on a given list of integers using binary search
method and for solving the tower of Hanoi problem
Logic
Logic
1. In case the number of discs are 1 then output would be 'Move disc n form
source_needle to destination_needle.
2. If not then do steps 3-5
3. Move n-1 discs recursively from source_needle to temp_needle
4. Move disc n from source_needle to destination_needle
5. Move n-1 discs from temp_needle to destination_needle
Adhit Mukesh Shet adhitms@gmail.com
WAP to construct a binary search tree of integers , to traverse the tree using all methods
Insert Function
Logic
1. Dynamically create a node and save it as the variable 'temp'
2. Update the information part of this node to the input element
3. Update the left and right link of this node as NULL
4. If the 'root' variable is NULL then assign 'temp' to 'root'.
5. Assign 'root' to 'cur', use this variable to traverse the linked list till the information
part of the node is not equal to input element and till the node is not equal to NULL.
Do steps 6-7 (cur points to the current node)
6. Assign the 'cur' to the variable 'prev'(prev points to the previous node)
7. If the input element is less than the information part of the current node then update
'cur' to the left link of the current node else update it to the right link of the current
node
8. If the input element is less than the information part of the previous node, then
update the left link of the previous node as NULL else update the right link of the
previous node as NULL
Inorder Traversal
Logic
1. If 'root' is NULL then return control to the calling function
2. If not then do steps 3-5
3. Traverse the left subtree in inorder
4. Print the root node
5. Traverse the right subtree in inorder
Preorder Traversal
Logic
1. If 'root' is NULL then return control to the calling function
2. If not then do steps 3-5
3. Print the root node
4. Traverse the left subtree in preorder
5. Traverse the right subtree in preorder
Postorder Traversal
Logic
1. If 'root' is NULL then return control to the calling function
2. If not then do steps 3-5
3. Traverse the left subtree in postorder
4. Traverse the right subtree in postorder
5. Print the root node
Adhit Mukesh Shet adhitms@gmail.com
WAP to support the following operations on a doubly linked list where each node consists of integers
1. Create a doubly linked list be adding each node at the front
2. Insert a new node to the left of the node whose key value is read as input
3. Delete the node of the given data, if it is found, other wise display appropriate message
4. Display the contents of the linked list
Logic
1. Dynamically create a node
2. On successful creation of the node do steps 3-6 else go to step 7
3. Assign 'first' to the right link of this node
4. Update the left link of the first node to this node
5. Initialize the left link of this node as NULL
6. Take the value of the node from the user and save it in the information part of this node
7. Return the node first to the calling function
Logic
1. Dynamically create a node
2. On successful creation of the node do steps 3-13 else go to step 14
3. Take the value of the specified node from the user
4. If the first node is NULL or if the first node is the specified node then call the insert at
the front of the linked list function
5. If not then assign the first node to 'trv'
6. While 'trv' is not equal to NULL and the 'trv' is not the specified node assign the value of
the right link of 'trv' to trv ( Do this to traverse the linked list and find the specified
node)
7. If 'trv' is not NULL then do steps 8-12 else go to step 13
8. Take the value of the new node from the user
9. Update the left link of the new node to the left link of the node 'trv'
10. Update the right link of the new node to 'trv'
11. Update trv to the left link of the new node
12. Update the right link of 'trv' to the new node. Go to step 14
13. Inform the user that the specified node was not found in the linked list
14. Return the node first to the calling function.
Logic
1. If first node is NULL then inform the user that the linked list is empty.
2. Assign first node to 'trv'
3. While 'trv' is not equal to NULL and the 'trv' is not the specified node assign the value of the
right link of 'trv' to 'trv'(Do this to traverse the linked list and find the specified node)
4. If 'trv' is NULL then inform the user that the specified node was not found.
Adhit Mukesh Shet adhitms@gmail.com
Display Function
Logic
1. If the first node is NULL then inform the user that the liked list is empty
2. If not then do steps 3-4
3. Assign first node to 'trv'
4. While trv is not equal to NULL print the contents of the node and also update the value of the
node 'trv' to its right link
Adhit Mukesh Shet adhitms@gmail.com
WAP using dynamic variables and pointers, to construct a singly linked list consisting of the following
information in each node: Student ID, Student Name and Semester. The operations to be supported are
1. The insertion operation
1. At the front of the list
2. At the back of the list
3. At any position in the list
2. Deleting a node based on ID. If the specified node is not found then display an error message
3. Searching a node based on student ID and update the information content. If the specified node
is not found then display an error message
4. Displaying all nodes in the list
Logic
1. Take the value of the Student ID from the user
2. If the node first is NULL then inform the user that the linked list is empty and to return control
to the calling function
3. If not then assign first to 'trv' and assign NULL to 'prev'
4. While 'trv' is not NULL and Student ID of the trv is not input Student ID assign the link of trv
to trv and assign trv to prev
5. If the node trv is NULL then inform the user that the required node was not found in the list and
return the control to the calling function
6. If not then assign the link part of prev as the link part of trv
7. Free the node trv
8. Return control to the calling function
Logic
1. Take the value of the Student ID from the user
2. If the node first is NULL then inform the user that the linked list is empty and to return control
to the calling function
3. If not then assign first to 'trv'
4. While 'trv' is not NULL and Student ID of the trv is not input Student ID assign the link of trv
to trv
5. If the node trv is NULL then inform the user that the required node was not found in the list and
return the control to the calling function
6. If not then take the new Student ID, Student Name and Semester from the user and update the
information part of this node
7. Return the control to the calling function
Logic
1. If the first node is NULL then inform the user that the linked list is empty
2. If not then do steps 3-4
3. Assign first node to 'trv'
4. While trv is not equal to NULL print the contents of the node and also update the value of the
node 'trv' to its link
5. Return the control to the calling function
Adhit Mukesh Shet adhitms@gmail.com
Q Insert Function
Logic
1. Dynamically create a node
2. On successful creation of the node do steps 3-8 else go to step 9
3. Assign first node to 'trv'
4. While the link of trv is not equal to NULL update the value of the node 'trv' to its link
5. Assign the link of this node as NULL
6. Assign the link of trv as this node
7. Take the value from the user and save it in the information part of this node
8. If first is NULL then assign this node as first
9. Return the node first to the calling function
Q Delete Function
Logic
1. If the first node is NULL then inform the user that the linked list is empty
2. If not then assign the value of first to dump
3. Update first to the link of first
4. Free dump
5. Return the node first to the calling function
Q Display Function
Logic
1. If the first node is NULL then inform the user that the linked list is empty
2. If not then do steps 3-4
3. Assign first node to 'trv'
4. While trv is not equal to NULL print the contents of the node and also update the value of the
node 'trv' to its link
5. Return the control to the calling function
Adhit Mukesh Shet adhitms@gmail.com
Push Function
Logic
1. Dynamically create a node
2. On successful creation of the node do steps 3-5 else go to step 6
3. Assign 'first' to the link of this node
4. Take the value from the user and save it in the information part of this node
5. Assign this node as first
6. Return the node first to the calling function
Pop Function
Logic
1. If the first node is NULL then inform the user that the linked list is empty
2. If not then assign the value of first to dump
3. Update first to the link of first
4. Display the information contained in the node dump.
5. Free dump
6. Return the node first to the calling function
Display Function
Logic
1. If the first node is NULL then inform the user that the linked list is empty
2. If not then do steps 3-4
3. Assign first node to 'trv'
4. While trv is not equal to NULL print the contents of the node and also update the value of the
node 'trv' to its link
5. Return the control to the calling function
Adhit Mukesh Shet adhitms@gmail.com
WAP to stimulate the working of a circular queue of integers using an array. Provide the following
operations
I. Insert
II. Delete
III. Display
Insert Function
Logic
1. If count(the variable indicating the number of values present in the circular queue ) is maximum
then inform the user that the circular queue is full.
2. If not then take the value to be inserted into the circular queue from the user
3. Update the location of the rear of the queue using modulus addition. i.e. rear = (rear+1)%MAX
(where MAX indicates the maximum number of values the circular queue can hold)
4. Save the input value at the rear of the circular queue
5. Increment the variable 'count'
Delete Function
Logic
1. If count is 0 then inform the user that the circular queue is empty
2. If not then display the element located at the front of the queue.
3. Delete this element by updating the front of the queue using modulus addition i.e.front=(front
+1)%MAX(where MAX indicates the maximum number of values the queue can hold)
4. Decrement the variable 'count'
Display Function
Logic
1. If the count is 0 then inform the user that the circular queue is empty
2. If not then assign front to trv
3. For count number of times do steps 4-5
4. Display the value located at location in the circular queue pointed to at by trv
5. Update the value of trv by modulus addition i.e. trv=(trv+1)%MAX
Adhit Mukesh Shet adhitms@gmail.com
WAP to stimulate the working of queue of integers using an array. Provide the following options on it
i. Insert
ii. Delete
iii. Display
Insert function
Logic
1. If the maximum number of values the array can take is rear+1, then inform the user that the
queue is full
2. If not then increment the rear by 1
3. Take the element to be entered into the queue from the user.
4. Save this element at the rear of the queue
5. If front of the queue is -1 then increment it by 1
Delete Function
Logic
1. If front is -1 or if front is greater than the rear then inform the user that the queue is empty. Also
assign both front and rear of the queue to -1
2. If not then display the front of the queue. This is the element to be deleted.
3. Increment the front of the queue by one.
Display Function
Logic
1. If front is -1 or if front is greater than the rear then inform the user that the queue is empty. Also
assign both front and rear of the queue to -1
2. If not then display every array element from front of the queue to its rear
Adhit Mukesh Shet adhitms@gmail.com
WAP to evaluate a valid postfix expression using stack. Assume that the postfix expression is read as a
single line consisting of non negative single digit operands and binary arithematic operators like plus,
minus, multiply and divide.
Evaluation function
Logic
1. Read each character from the postfix expression
2. If the characters are operands then push them into the stack
3. If the characters are operators then do steps 4-7
4. Pop an operand from the stack and save it as operand2
5. Pop another operand from the stack and save it as operand1
6. Perform the required operation on operand1 and operand2
7. Push the result obtained into the stack
8. Do the steps 1-7 till the end of the postfix expression i.e. until '\0' is encountered
Push function
Logic
1. Increment the top variable
2. Read the character of the postfix expression to be entered into the stack
3. Save this character at the top of the stack
Pop Function
Logic
1. Return the character saved at the top of the stack to the calling function
2. Decrement the top of the stack
Adhit Mukesh Shet adhitms@gmail.com
WAP which accepts the IP address in decimal dot format and converts it into 32 bit long integer using
strtok library function and unions
Logic
1. Take the IP address in the dot format from the user
2. Use the strtok function to separate the IP address into different fields
3. Pass the variable name of the IP address when calling the strtok function for the 1st time, from
then on pass NULL as the 1st argument. The field separator “.” is to passed as the 2nd argument
in all cases.
4. Use the strtol function to convert each field into its 32bit long integer form. Pass the string
name, the end pointer and radix as its arguments
5. Print the 32 bit long integer value of the given IP address
Adhit Mukesh Shet adhitms@gmail.com
Write a C program to construct an array of integers and to perform the following operations on it. (i)
Insert (ii) Delete (iii) Search by an item (iv)Search by position (v) Display
Pseudo Code
Search Function
Input Search element
Output Notify the user if Search was successful or not. If the search was successful then do display the
position of the found element
Logic
1. Read the Search element
2. Search If the search element is in the given array using Linear Search
3. From the base address of the array till the last element in the array which is pointed to by the
no. of elements variable, read every element and check if the array element is equal to the
given search element
4. If the given search element is found ,then note the position of the element in the array and
display it to the user
5. If the search is not successful then notify the user
Delete Function
Input To delete by position or by element, if to delete by position then the position of the
element to be deleted in the array. If to be deleted by element, then search function
Output If to delete by element then notify the user if the element in not found in the array
Logic
1. Ask the user if we have to delete by position or by element
2. If an element has to be deleted by position then ask the user to enter the position.
3. Read the position.
4. To delete an element at the given position, read the array content at (position +1) location. Copy
the contents of this location to the given position. Do so forth till the last array element is
moved one location forward.
5. Decrement the count of number of array elements by one.
6. To delete by element, ask the user to enter the element.
7. Read the element
8. Call the Search function to find if the element exists in the array. In case the element does not
exist then notify the user.
9. In case the element exists in the array then delete the element by transferring the contents of the
next array element into its location and so forth
10. Decrement the count of number of array elements by one.
Insert Function
Input The position at which the element is to be inserted, the element to be inserted
Output nil
Logic
1. Ask the user to enter the position where the element is to be inserted.
2. Read the position
Adhit Mukesh Shet adhitms@gmail.com
3. Read the last element in the string and copy its value to its immediate next location. Now read
the last but one location and copy its contents to the immediate next location. Do so forth till the
required position is reached.
4. Ask the user to enter the element to be inserted and save it at the given position
5. Increment the count of number of array elements by one.
Display Function
Input The base address of the array, number of elements in the array
Output The contents of the Array.
Logic
1. Read the base address of the array
2. Read the maximum number of array elements
3. From 0th element of the array till the last element of the array, print the value of the array
elements on the console.
Adhit Mukesh Shet adhitms@gmail.com
Pseudo Code
String copy Function
Input Input string
Output Copied String and the Input String
Logic
1. Read the Input String.
2. Begin from the start of the string, read every character of the input string and copy it to another
string till ‘\0’ is encountered
3. When ‘\0’ is encountered in the input string, come out of the loop.
4. Append ‘\0’ to the end of the Copied String
String Concatenate Function
Input The two input strings
Output The concatenated string
Logic
1. Read the 2 input Strings
2. From the 1st element of the String, Increment the counter of the 1st string till ‘\0’ is reached
3. Replace ‘\0’ with a blank space ‘ ‘
4. Increment the counter of the 1st array once.
5. Now read every character of the 2nd string from the start and copy it to the present counter
location in the 1st string
6. Do this till ‘\0’ is encountered in the 2nd String.
7. Now append ‘\0’ to the end of the 1st String.
8. The 1st String is now the concatenated String.
Adhit Mukesh Shet adhitms@gmail.com
Pseudo Code
Function to create records
Input Number of Records, record details like Student id number, name, Marks scored in 3 subjects
Output Save the record details in a file
Logic
1. Read the number of records the User wants to create
2. Open a file in write mode
3. From 0 to the number of record times loop steps 4-9.
4. Read the Student id Number
5. Read the Student Name
6. Read Marks1
7. Read Marks2
8. Read Marks3
9. Write these Student Details in the file.
10. Close the file.
Write a C program to construct a stack of integers and to perform the following operations on it:
Push
Pop
Display
The program should print appropriate messages for stack overflow, stack underflow and stack empty.
Pseudo Code
Push Function
Input Maximum number of Stack elements, the element to be pushed into the Stack, top
Output Notify the user if Stack Overflow conditions exist.
Logic
1. Check if the Stack is full i.e. for Stack Overflow condition
2. If the Stack Overflow condition exists then notify the user
3. If the Stack is not full then increment the value of the top variable
4. Ask the user to enter the variable to be pushed into the stack
5. Read this element and save it at the location in the stack pointed to by the top variable
Pop Function
Input Maximum number of Stack elements, top
Output Notify the user if Stack Underflow conditions exist, the element to be deleted.
Logic
1. Check if the Stack is empty i.e. for Stack underflow conditions
2. If the Stack Underflow conditions exist then notify the user
3. If the Stack Underflow conditions do not exist then notify to the user the element to be deleted
from the stack
Decrement the top variable
Display Function
Input Top
Output Notify the user if the Stack is empty, the stack elements
Logic
1. Check if the Stack is empty
2. If so notify the user that the Stack is empty
3. If not, then read the contents of the stack pointed to at by the top variable decrementing it till 0.
Print these values on the console.
Adhit Mukesh Shet adhitms@gmail.com
Write a C program to convert and print a given valid parenthesized infix arithmetic expression to
postfix expression. The expression consists of single character operands and the binary operators +
(plus), - (minus), * (multiply) and / (divide).
Precedence Function
Input Operator
Output Precedence Value
Logic
1. Read the operator from the String
2. If ‘$’ or ‘^’ is the operator then precedence value is 3
3. If ‘/’ or ‘*’ is the operator then precedence value is 2
4. If ‘+’ or ‘-‘ is the operator then precedence value is 1
5. If ‘(‘ is the input then precedence value is 0
6. For ‘#’ the precedence value is -1
Push Function
Logic
1. Increment the value of the top pointer variable
2. The value to be pushed into the stack is read from the calling function
3. This variable is saved at the location in the stack pointed at by top pointer variable
Pop Function
Logic
1. Return the value of the stack element pointed at by the top pointer variable to the calling
function
2. Decrement the value of the top pointer variable