Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
10 views11 pages

Tim Case Study

Uploaded by

willtraveltime
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views11 pages

Tim Case Study

Uploaded by

willtraveltime
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 11

Algorithm Source code Output

1. Initialize an Empty
Array:

o Create an empty
array called array.

2. Input Phase:
 Display a message
prompting the user to
enter elements.
 Repeat the following until
the user types 'done' or
'DONE':
o Read user input and
store it in value.
o If value is 'done' or
'DONE', exit the
loop.
o Append value to
array.
3. Display Current Array:

 Print the contents of


array.

4. Define Menu Function:


 Create a function
display_menu() that
prints the following
options:
o A. Update Element
o B. Insert Element
o C. Retrieve Element
o D. Delete Element
o E. Exit
5. Define Update
Function:
 Create a function
update_element():
o Read user input for
the element to
update (update).
o Initialize found as
False.
o For each index i in
array:
 If array[i] is
equal to
update:
 Set found
to True.
 Read user
input for
new_valu
e.
 Replace
array[i]
with
new_valu
e.
 Print a
message
confirmin
g the
update
and break
the loop.
o If found is still False,
print a message
indicating that the
element was not
found.
o Print the updated
array.
6. Define Insert Function:
 Create a function
insert_element():
o Read user input for
the element to
insert (value).
o Read user input for
the index to insert
(index_str) and
convert it to an
integer.
o If index is valid (0 to
length of array):
 Create a new
array
new_array and
copy elements
from array to it
up to index.
 Append value
to new_array.
 Append the
remaining
elements from
array to
new_array.
 Update array
to be
new_array.
 Print a
message
confirming the
insertion.
o If index is invalid,
print an error
message.
o Print the updated
array.

7. Define Retrieve
Function:
 Create a function
retrieve_elements():
o If array is empty,
print a message
indicating that no
elements are
available.
o Read user input for
the element to find
(value_to_find).
o Initialize position to
-1.
o For each index i in
array:
 If array[i] is
equal to
value_to_find,
set position to i
+ 1 and break
the loop.
o If position is greater
than 0:
 Print the
contents of
array with their
positions.
 Print a
message
indicating the
position of
value_to_find.
o If not found, print a
message indicating
that the element is
not found.
8. Define Delete
Function:
 Create a function
delete_element():
o Read user input for
the element to
delete (delete).
o Initialize found as
False and create an
empty array array2.
o For each index i in
array:
 If array[i]
equals delete
and found is
False:
 Set found
to True
and print
a
message
confirmin
g
removal.
 Otherwise,
append array[i]
to array2.
o If found is still False,
print a message
indicating that the
element was not
found.
o Update array to be
array2.
o Print the updated
array.
9. Main Menu Loop:
 Repeat the following until
the user chooses to exit:
o Call display_menu()
to show options.
o Read user input for
the option.
o If option is 'A' or 'a',
call
update_element().
o If option is 'B' or 'b',
call
insert_element().
o If option is 'C' or 'c',
call
retrieve_elements().
o If option is 'D' or 'd',
call
delete_element().
o If option is 'E' or 'e',
print a goodbye
message and exit
the loop.
o If the input is
invalid, print an
error message.
Conclusion
o This algorithm captures
the essential flow and
logic of your code,
making it easier to
understand and follow.

You might also like