Hi there!
I'm studying for my exam and I've came across a problem...
How do I use insertion sort algorithm if I have an empty 20 slot array that is going to store cellphones.
When the program runs its supposed to display a menu with 8 options.
1. Add new cellphone
2. Show all cellphones
3. Show the most expensive one.
4. Show all phones with touch screen
5. Show the design of the phones
6. Show all phones sorted in alphabetical order
7. Save to file.
0. Quit
I'm stuck at the sorting, have no idea what to do :-/
There may be a better sorting algorithm but our teacher wants us to use insertion sort, but he has never showed us how to use it with strings only with ints.
this is how my function looks like
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
void showModelSorted(Cell cell[], int nrOfCells)
{
string temp;
int i;
for(i=1;i<nrOfCells;i++)
{
temp=cell[i];
int j;
for(j=i-1;j>=0 && cell[j]>temp;j--)
{
cell[j+1]=cell[j];
}
cell[j+1]=temp;
}
for(i=0;i<nrOfCells;i++)
cout<<cell[i]<<" ";
cout<<endl;
}
|
but how does visual studio know that lets say Nokia N900 should be printed before Sony Ericsson Xperia x10?
Any kind of help is appreciated!