#include #include //for the iomanipulator setw ("set width") #include using namespace std; //Sort the 2021 median household income for each state in increasing order. //https://en.wikipedia.org/wiki/List_of_U.S._states_and_territories_by_income int main() { int a[] { 53913, //Alabama 77845, //Alaska 69056, //Arizona 52528, //Arkansas 84907, //California 82254, //Colorado 83771, //Connecticut 71091, //Delaware 63062, //Florida 66559, //Georgia 84857, //Hawaii 66474, //Idaho 72205, //Illinois 62743, //Indiana 65600, //Iowa 64124, //Kansas 55573, //Kentucky 52087, //Louisiana 64767, //Maine 90203, //Maryland 89645, //Massachusetts 63498, //Michigan 77720, //Minnesota 48716, //Mississippi 61847, //Missouri 63249, //Montana 66817, //Nebraska 66274, //Nevada 88465, //New Hampshire 89296, //New Jersey 53992, //New Mexico 74314, //New York 61972, //North Carolina 66519, //North Dakota 62262, //Ohio 55826, //Oklahoma 71562, //Oregon 68957, //Pennsylvania 74008, //Rhode Island 59318, //South Carolina 66143, //South Dakota 59695, //Tennessee 66962, //Texas 79449, //Utah 72431, //Vermont 80963, //Virginia 84247, //Washington 51248, //West Virginia 67125, //Wisconsin 65204 //Wyoming }; int n {size(a)}; //the number of elements in the array for (int *p {a+n-1}; p > a; --p) { //Start with p pointing to last eleme for (int *q {a}; q < p; ++q) { //q[0] should be less than or equal to q[1]. //If q[0] and q[1] are in the wrong order, if (q[0] > q[1]) { //Swap the values of q[0] and q[1]. int temp {q[0]}; q[0] = q[1]; q[1] = temp; } } //At this point, the value in *p is in the correct place. } for (int *p {a}; p < a+n; ++p) { //p-a is the subscript of each array element. //Add 1 because human beings like to count starting at 1. cout << setw(2) << p-a+1 << " " << *p << "\n"; } return EXIT_SUCCESS; }