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
The internet's data gathways rely on what kind of hardware devies to route data to its destination?
Gennadij [26K]

Answer:

router

Explanation:

4 0
3 years ago
I want know answer for best way to copy formula on MS Access
marusya05 [52]

Answer:

copy and paste is alternate

5 0
2 years ago
How many miss Dragon Ball Abridged?
Troyanec [42]

What is "Dragon Ball Abridged"?

3 0
3 years ago
Read 2 more answers
Write a class called Product. The class should have fields called name, amount, and price, holding the product’s name, the numbe
vichka [17]

Answer:

public class Product {

//Declaring the fields

   private String name;

   private int amount;

   private double price;

   //Constructor

   public Product(String name, int amount, double price) {

       this.name = name;

       this.amount = amount;

       this.price = price;

   }

   // The method get_price

   public double get_price(int amount){

       // amount of goods less than 10

       if(amount<10){

           double zeroDiscPrice;

           zeroDiscPrice = this.price;

           return zeroDiscPrice;

       }

       // amount of goods less than 100

       else if(amount>=10 && amount<100){

           double tenPercentDiscPrice;

           tenPercentDiscPrice = this.price-(this.price*0.1);

           return tenPercentDiscPrice;

       }

       // amount of goods greater than 100

       else{

           double twentyPercentDiscPrice;

           twentyPercentDiscPrice = this.price-(this.price*0.2);

           return twentyPercentDiscPrice;

       }

   }

}

Explanation:

The class is implemented in Java programming language

Three member variables (fields) are declared as described in the question

A constructor is created to initialize an instance of the class

The method get_price() as created uses a combination of if...else if....else To determing the price based on the amount of items bought as described in the question.

5 0
3 years ago
Alice has an item x and Bob has a set of five distinct items y1, y2, y3, y4 and y5. Design a protocol through which Alice (but n
lukranit [14]
I guess it will be 4 yards each hopes it will help u :)
4 0
2 years ago
Other questions:
  • Select the instances in which you should include a comma.
    14·1 answer
  • The procedure call mystery(38) will yield which output? __________ a) 0 12 b) 12 0 c) 1 1 0 2 d) 1 1 1 1 e) 2 0 1 1 public void
    11·1 answer
  • I need help in creating a Java Program; To calculate the chapter from which you solve the programming exercise, below are the re
    7·1 answer
  • What is contrast (in Photography)?
    14·1 answer
  • You just settled in for some study time at the local coffee shop, and you pause long enough to connect your smartphone to the Wi
    7·1 answer
  • What is the most likely to be a possible physical attack?
    7·2 answers
  • Create a relational database table in Microsoft Excel for the grocery store of 20 employers.
    12·1 answer
  • Which tools do meteorologists use to collect data about the weather?
    13·2 answers
  • Bộ mã I mã hóa được nhiêu kí tự
    12·1 answer
  • Write the pseudocode for this flowchart
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!