answersLogoWhite

0


Best Answer

Sorting arrays (of any type) can be achieved with the C++ standard library std::sort function:

std::array<int, 5> a {9, 3, 5, 1, 7}; // fixed-length array

std::vector<int> b {9, 3, 5, 1, 7}; // variable length array

int c[] = {9, 3, 5, 1, 7}; // C-style array

std::sort (a.begin(), a.end());

std::sort (b.begin(), b.end());

std::sort (c, c+5);

User Avatar

Wiki User

6y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the code of sorting out an given unsorted array in text file for c plus plus?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

How do you sort the given contents of an array?

You would sort the given elements of an array by a bubble sort or heap sort code!!


What is the code for sorting in C plus plus?

There are many sorting algorithms. One of the simplest to implement is the insertion sort. The following template function will sort an array of any type T that supports the less-than operator. It works by splitting the array into two subsets, where the left portion is sorted and the right is unsorted. Initially, the sorted portion has just one element since a set of one element can always be regarded as being sorted. We then work our way through each of the unsorted elements, from left to right, inserting them into their correct place in the sorted portion. To do this we need to store the current unsorted value thus creating a gap at the beginning of the unsorted portion. This gap then becomes the last element of the sorted portion, reducing the unsorted portion by one element. We then work our way through the sorted elements starting with the element to the left of the gap. If the stored value is less than the current element's value then we copy that element into the gap, thus moving the gap one position to the left. We continue in this manner until gap is at index 0 or the stored value is not less than the element to the left of the gap. We then place the stored value in the gap. We repeat this for all unsorted elements until there are none left, at which point the array is completely sorted. template&lt;typename T&gt; void sort(std::vector&lt;T&gt;&amp; v) { if( v.size()&gt;1 ) { for( size_t i=1; i&lt;v.size(); ++i ) { T t = v[i]; size_t gap=i; while( gap &amp;&amp; t&lt;v[gap-1] ) v[gap]=v[gap--]; v[gap]=t; } } }


What is the sorting code for keystone bank in Nigeria?

082150001


What natwest code has sorting code 515003?

10 Southwark Street London SE1 1TJ


What Halifax branch has sorting code 11-05-05?

Peckham


Create a mark list using array with structure?

sorce code for student mark list usig array


Which ulster bank branch has the sort code 986663?

This is the sorting code of an Ulster Bank e-Savings Online Account


Can you help me with the C plus plus code of the program which has 10 index of array it adds 5 into every even elements of the array and then it subtracts 10 into the odd elements of the array?

int array[10] = {...}; for (int i = 0; i &lt; 10; ++i) { if (i % 2 == 0) array[i] += 5; else array[i] -= 10; }


What is the swift code for regions bank?

RegionsBank's SWIFT code is UPNBUS44.more bank code (SWIFT - BIC, Routing Number, Sorting Code) on http://www.bankers-telenet.com


Can you write a source code to find the sum and the largest number of a given array?

In Java, assuming you already created an array of int's, called myArray:int max = myArray[0];int sum = 0;for (int i = 0; i < myArray.length; i++){sum += myArray[i];if (myArray[i] > max)sum = myArray[i]}


How 2 write c code of array data structure?

An example: int array [10]; yaaa this is write but for a simple programs on array and all data structure visit codingdatastructure.blogspot.com


What is the meaning of the numbers in your zip-code?

They assist in the sorting of mail. To help pinpoint where you're located.