Answer to Question #241225 in Algorithms for Selma

Question #241225
Identify the steps you would take to carry out each of the following operations on an array data
structure and then implement an algorithm in pseudocode to solve problem as guided by the steps you
have identified.
2. Write a function deleteLast() that accepts an array and Delete the last element in the array and display
the contents of an array after deletion operation.
3. Find an element x in an array and return the index of x, if found. Otherwise “print element x is not
in the list”.
4. Display the last 3 elements in the array
1
Expert's answer
2021-09-23T12:12:57-0400
2. Write a function deleteLast() that accepts an array and Delete the last element in the array and display
the contents of an array after deletion operation.
Answer:
Start function deleteLast(numbers[]):
   for i as integer = arraySize-1 to arraySize do
       numbers[i]=numbers[i+1]
   arraySize=arraySize-1
Stop




3. Find an element x in an array and return the index of x, if found. Otherwise “print element x is not
in the list”.
Answer:


Start function FindElement(numbers[],x):
  for i as integer = 0 to arraySize do
       if numbers[i]==x then
          return i
  Print message: "The element x is not in the list"
  return -1
Stop
4. Display the last 3 elements in the array


Answer:
Start function DisplayLast3Elements(numbers[]):
  for i as integer = arraySize -3 to arraySize do
      Display numbers[i]
Stop

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS