Hey all!
I was hoping to get some help with a problem.
My assignment requires that I write code that will sort an array with pointers. It requires that I take the original array (for.example: iint NumList[] = {5, 34, 32, 25, 75, 42, 22, 2}; and output the array in ascending order, its original order, and its descending order.
My problem isn't sorting the array into the different orders, it is doing it with pointers.
Right now I am sorting it correctly, just not the way I am supposed to sort it.
Hopefully, somebody could help me out some!
Thanks in advance to whomever is awesome enough to help me!!
This is what I have right now:
CODE
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
int NumList[8] = {5, 34, 32, 25, 75, 42, 22, 2};
int *ascend = NumList;
int *descend = NumList;
int Swap;
//cout << "Ascending" << setw(16) << "Original " << setw(16) << "Descending" <<"\n";
//cout << "=========" <<setw(15)<< "========" << setw(16) << "==========" <<"\n";
cout << "Original\n";
for(int ctr = 0; ctr < 8; ctr++)
{
cout<< setw(6) << NumList[ctr]<<"\n";
}
cout<<"\n";
//cout << "\n\n";
for(int i = 0; i < 7; i++)
for(int ii = 0; ii < 7; ii++)
if (NumList[ii] > NumList[ii + 1])
{
Swap = NumList[ii];
NumList[ii] = NumList[ii + 1];
NumList[ii + 1] = Swap;
}
cout << "Ascending\n";
for (int iii=0; iii<8; iii++)
cout<< setw(6) << NumList[iii]<<"\n";
//for (int jj = 0; jj < 8; jj++)
//cout << NumList[jj] << " ";
//int aArray[8] = NumList[iii]
//cout << "\n\n";
//cout << "Original\n";
//for (int i = 0; i < 8; i++)
//cout << setw(6) << NumList[i]<<"\n";
cout << "\nDescending\n";
for (int jiii = 7; jiii >= 0; jiii--)
cout << setw(6) << NumList[jiii] <<"\n";
cout << "\n\n";
//system("pause");
}