|
Hi there i have this problem the question is:
write an algorithm to sort an array of integers.
now i have had a go at this and my solution works shown below:
list<int> number;
list<int>::iterator i;
int j =0;
int Input[] = {1,3,5,7,3,9,11,54,32};
for (j =0; j < 9; j++) {
number.push_back(Input[j]);
}
cout<<"the contents are "<<endl;
i = number.begin();
while (i != number.end()) {
cout<< *i <<" ";
i++;
}
cout<<endl;
number.sort();
cout<<"the sorted contents are "<<endl;
i = number.begin();
while (i != number.end()) {
cout<< *i <<" ";
i++;
}
cout<<endl;
Now the problem is with this implemenation i am just sorting an array of stored numbers but what if i wanted the user to enter numbers and pass this into an array then put the array into a list and sort it. I tried to do this but i just couldn't get the hang of the EOF operator and coudln't stop the input using that.
If anyone can help me with user entry using the EOF operator into the array then putting this array into the stl list i will be most gratefull.
Thanks
Iffy.
|
|
|
|
|
|
|
|