answersLogoWhite

0

Use insertion sort. First, add a new element to the end of the array. The value of this new element does not matter at this stage, all we are really doing is creating a place-holder. We now look at the element to the left of the place-holder and, if it is greater than the value we are inserting, we copy that element's value to our place-holder, effectively moving it one element to the right and moving our place-holder one element to the left. We continue in this manner until the element to the left of the place-holder is not greater than the value we are inserting, or the place-holder reaches the beginning of the array. We then copy our new value into the place-holder.

In effect, the place-holder creates a "gap" in the array and we simply move that gap to the left until it finds its correct place according to the value we are inserting. The algorithm works even when there are not (yet) any elements in the array.

Note that if the last element of the array is not greater than the new value, the gap does not move (the new value has found its place at the end of the array). Note also that elements of equal value are kept in stable order (in the same order they were input).

User Avatar

Wiki User

9y ago

What else can I help you with?

Related Questions

Is position scalar or vector?

Position is a vector quantity.


What is position vector in physics?

A position vector tells us the position of an object with reference to the origin


Starting from a location with position vector, what is the direction to the keyword?

Starting from a location with a position vector, the direction to the keyword can be determined by calculating the angle between the position vector and the vector pointing towards the keyword.


Is position a vector quantities?

Yes, it is a vector quantity.


WHAT POSITION VECTOR?

A position vector is a vector that represents the location of a point in space relative to a reference point or origin. It specifies the distance and direction from the origin to the point. In three-dimensional space, a position vector is typically denoted as <x, y, z>.


What can describe the displacement of an object?

The displacement of an object is the change in position of the object from its initial position to its final position. It is a vector quantity that has both magnitude and direction. Mathematically, it can be calculated by subtracting the initial position vector from the final position vector.


Is the position scalar or vector quantity?

Vector-it has both magnitude and direction


When was Asymptote - vector graphics language - created?

Asymptote - vector graphics language - was created in 2004.


What is an ordered list of data structure using c plus plus?

An ordered list of data in any programming language is simply a sorted array or list. In C++ this can either mean a sorted array, vector, list or forward list.


When an object moves from one position to another the vector from the initial position to the final is called?

The vector from the initial position to the final position of an object is called the displacement vector. It represents the overall change in position of the object, including both the direction and magnitude of the movement.


Vector method to find out the acceleration of a particle is -wwrwhere angular velocity is w?

To find the acceleration of a particle using the vector method, you can use the equation a = r x (w x v), where "a" is the acceleration, "r" is the position vector, "w" is the angular velocity vector, and "v" is the velocity vector. The cross product (x) represents the vector cross product. By taking the cross product of the angular velocity vector with the velocity vector and then multiplying the result by the position vector, you can find the acceleration of the particle.


How can one determine the velocity vector from a given position in a physical system?

To determine the velocity vector from a given position in a physical system, you can calculate the derivative of the position vector with respect to time. This derivative gives you the velocity vector, which represents the speed and direction of motion at that specific point in the system.