1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
pashok25 [27]
3 years ago
5

Write a function insert that takes an array of integers in ascending order, the number of integers currently in the array, the t

otal size of the array, and an integer to insert into the array. The function should insert the given integer into the array such that the array remains in sorted order. If the array is already full, the array should remain unchanged. The function should return the new number of elements in the array.
Computers and Technology
1 answer:
Andrei [34K]3 years ago
3 0

Answer:

The code is written in MATLAB

function insert(array,integer,capacity,newInt)

if integer == capacity %if the array is full, the function returns the original array

result = array;

else

if newInt < array(1) %If the new integer is less than the first element, it copies the new integer as the new first element

array = [newInt array];

elseif newInt > array(end) %If the integer is greater than the last element, it copies the new integer as the new last element

array = [array newInt];

else %If the new integer is inside the array, then it checks its new place

for i = 1:length(array)-1

if array(i+1) > newInt % once the place of the new integer is found, the rest of the array is saved in a dummy array

dummy = array(i+1:end);

array(i+1) = newInt;

array(i+2:end) = '';%the rest of the array is deleted

array = [array dummy]; %concatanate the dummy array with the newInteger inserted array

break

end

end

end

end

fprintf('The inserted integer is %g\n', newInt);

fprintf('The new array is \n',array);

disp(array)

You might be interested in
How to order reference list in apa format?
Brums [2.3K]
<span>Title. Label this page References, centered in plain text.Spacing. Make sure to double space throughout.Order. List the sources in alphabetical order by the authors' last names. ...<span>Indentation. Do not indent the first line in the citation; however, you must indent any additional lines 5 spaces in the citation.</span></span>
5 0
3 years ago
Pressing and holding _______ while clicking enables you to select multiple contiguous files or folders.
liq [111]

Answer:

Hi LizBiz! The answer is Ctrl key on Windows, or Command key for Mac.

Explanation:

The Ctrl (Windows) key or equivalent Command key on Mac has a special purpose which allows special operations to be performed when combined with another action, such as clicking on multiple pictures or files for selection.

8 0
3 years ago
What is full form of RAM??? ​
stepladder [879]

Answer:

Random Access Memory, it's used to store working data and machine codes

Explanation:

Hope it helped !
Adriel

7 0
2 years ago
Read 2 more answers
A computer ____ is the amount of data (measured in bits or bytes) that a cpu can manipulate at one time
garik1379 [7]

A computer BIT is the amount of data that a CPU can manipulate at one time.

8 0
3 years ago
Which type of unshielded twisted pair (UTP) is commonly used in Ethernet 10BASE-T networks, which carry data at a rate of 10 Mbp
tino4ka555 [31]

Answer:

Category 3 (CAT3) Unshielded Twisted Pair cable

Explanation:

A Category 3 (CAT3) Unshielded Twisted Pair cable is a cable that makes use of the conductivity of copper to transmit data and power. These cables are an older standard for Ethernet cables and can handle data speeds of up to 10mbps.The succeeding standard for Ethernet cables include CAT5 which has speeds of up to 100 mbps, CAT 3 is mostly used in applications where speed is not of great importance such as in PBXs and VoIP telephone systems.

6 0
3 years ago
Other questions:
  • Which group allows you to add notes to your presentation?Ella has finished drafting her presentation. What should she do next?
    15·2 answers
  • Which of the following types of access controls do not describe a lock? (a)- Directive (b)- Physical (c)- Preventative (d)- Dete
    8·1 answer
  • What are the Database used in RDBMS and DBMS<br>please answer immediately​
    10·1 answer
  • What is meant by backing up files through cloud computing?
    5·2 answers
  • Instructions:Select the correct answer.
    8·2 answers
  • Top 5 best comedy or action movies.
    9·2 answers
  • Who invented the Bluetooth device​
    12·1 answer
  • Discuss the role of the concept behind the "Internet of Things (IoT)" in today's digitally connected society.
    11·1 answer
  • A binary search algorithm ____________ an ordered list in<br> half to find an item.
    13·1 answer
  • China sends a computer virus that shuts down telephone service in the United States. In retaliation, the United States hacks int
    13·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!