It's hardly the most efficient way to sort integers. Integers are primitive data types, so it's actually quicker to sort the integers directly rather than point at them. Pointers just add an unnecessary level of indirection. Pointers should only be used for complex data types for which copying/moving would result in greater inefficiency than would otherwise be incurred through pointer manipulation.
#include<iostream>
#include<vector>
int main()
{
// instantiate a vector of unsorted integers
std::vector<int> v = {7,3,5,2,9,4,1,6,8};
// instantiate a vector of pointers to the integers in the vector
std::vector<int*> p;
for (size_t i=0; i<v.size(); ++i)
p.push_back (&v[i]);
// sort the pointers (uses insertion sort algorithm):
for (size_t i=1; i<p.size(); ++i)
{
int* x=p[i];
size_t gap = i;
size_t pre = i-1;
while (gap && *x<*p[pre])
{
p[gap--] = p[pre--];
}
p[gap]=x;
}
// print to prove the sorting worked:
std::cout << "Original order:\t\t\t";
for (size_t i=0; i<v.size(); ++i)
std::cout << v[i] << '\t';
std::cout<<std::endl;
std::cout << "Sorted order (by pointer):\t";
for (size_t i=0; i<p.size(); ++i)
std::cout << *p[i] << '\t';
std::cout<<std::endl;
}
In Maths, we often talk about ascending and descending order. Ascending order is writing numbers from smallest to largest. Descending order is writing numbers from largest to smallest.
public class BubbleSortAscendingOrderDemo { public static void main(String a[]) { //Numbers which need to be sorted int numbers[] = {23,5,23,1,7,12,3,34,0}; //Displaying the numbers before sorting System.out.print("Before sorting, numbers are "); for(int i = 0; i < numbers.length; i++) { System.out.print(numbers[i]+" "); } System.out.println(); //Sorting in ascending order using bubble sort bubbleSortInAscendingOrder(numbers); //Displaying the numbers after sorting System.out.print("Before sorting, numbers are "); for(int i = 0; i < numbers.length; i++) { System.out.print(numbers[i]+" "); } }
Sort the array then traverse the array, printing the element values as you go.
Ascending means to increase or rise. You can ascend stairs, for example, by climbing them. a pattern of numbers can be ascending if each number increases, such as 1, 2, 3, 4, 5.Ascending is used to describe the return of Jesus from earth to heaven after his resurrection.ok thanks!!Going upwards. In different contexts it could mean increasing, getting bigger or climbing.
No. They can be sorted either ways. Ascending or Descending.
sorry
draw a flow chart to arrange 3 numbers in ascending order
vhdl code for ascending order of numbers
ascending
ascending order
In Maths, we often talk about ascending and descending order. Ascending order is writing numbers from smallest to largest. Descending order is writing numbers from largest to smallest.
Ascending is an order in which things can be sorted. Ascending would be going from A to Z or lowest to highest numbers or earliest to latest dates.
largest to smallest
In ascending order, perhaps!
Ascending means increasing in value or moving higher, while descending means decreasing in value or moving lower. In a numeric sequence, ascending would go from lowest to highest, while descending would go from highest to lowest.
The data that is being organized in ascending or descending order is the numbers or the alphabet. Ascending means is from lowest to highest and descending means from highest to lowest.
This is known as arranging the numbers in ascending order.