Sei sulla pagina 1di 2

INSERTION IN ONE DIMENSIONAL ARRAY

AIM: To insert an element into a sorted one dimensional integer array


Algorithm for main():
Step 1: Start.
Step 2: Accept the number of elements of the array in the variable n.
Step 3: Accept the x number of elements in to the array a[]. Enter no. of elements you want to
enter as x. Assign u=x-1.
Step 4: Repeat the steps 5 and 6 till rep=’y’.
Step 5: i Accept the elements to be inserted in the variable item.
i. Call the function insert() with the array ‘a’,item and n as argument.
Step 6: Accept the value in rep to continue or to end.
Step 7 : Stop.
Algorithm for insert():
Step 1: If u=n-1 then display “Overflow”.
Step 2: If the item is lesser than the first element of the array, initialize pos=0.
i. Initialize i=0.
ii. Repeat (iii) and (iv) till i<=u.
iii. If the array element in the ith position is lesser than or equal to the item and if the item is
lesser than or equal to the array element in the (i+1)th position then initialize pos=i+1.
iv. Increment i by 1.
Step 3: If i=u then assign pos=u+1.
Step 4: Initialize j=u+1.
Step 5: Repeat the steps 6 and 7 till j>pos.
Step 6: Initialize the array element in the (j-1)th position to the element in jth position.
Step 7: Decrement j by 1.
Step 8: Initialize the array element in the pos position with the item.
Step 9: Increment u by 1.
Step 10: Display the resultant array.
Step 11: Return.

DELETION IN ONE DIMENSIONAL ARRAY

Algorithm for main():


Step 1: Start.
Step 2: Accept the number of elements of the array in the variable n.
Step 3: Accept the x number of elements in to the array a[]. Enter no. of elements you want to
enter as x. Assign u=x-1.
Step 4: Repeat the steps 5 AND 6 till rep=’y’.
Step 5: i Accept the elements to be deleted in the variable item.
ii Call the function delete() with the array ‘a’, item and n as argument.
Step 6: Accept the value in rep to continue or to end.
Step 8: End.

Algorithm for delete():


Step 1: Initialize flag=0, i=0.
Step 2: If u=0 then display “Underflow Condition”.
Step 3: Repeat the steps 4 and 5 till i<n.
Step 4: If the array element in the ith position is equal to the item, then initialize pos=i,flag=1,break
out of the loop.
Step 5: Increment i by 1.
Step 6: If flag=0, display “item not found”.
Step 7: Initialize i=pos.
Step 8: Repeat the steps 9 and 10 till i<u.
Step 9: Initialize the array element in the (i+1)th position to the array element in the ith position.
Step 10: Increment i by 1.
Step 11: Decrement u by 1.
Step 12: Display the resultant array.
Step 13: Return.
Text File Handling

Aim: To illustrate the concept of Text files


Algorithm:
1. Start
2. Definition of function to write in the textfile
(i)Open the file in writing mode using file object
(ii) Reading the text from the user
(iii)Writing the line on the file
(iv) Accepting the users choice to continue or not
(v) Closing the file stream
3. Definition of function to read from the text file
(i)Open the file in reading mode using file object
(ii)Reading each character and incrementing the respective counter
(iii) Display the total count of uppercase, lower case, digits and spaces
(iv) Closing the file
4. End

BINARY FILE
Aim: To illustrate the concept of Binary files
Algorithm
1. Start
2. Definition of the class
3. Declaration of the file object in fstream and ios::binary mode
4. Declaration of the class object
5. Definition of the Main Menu
6. Accepting the users choice
7. Appending or searching and displaying the records in the data file as per the users choice
8. Disconnecting the file stream
9. End

Potrebbero piacerti anche