Creating Sorting class

S

spider

Hi Guys

I am planning to design a sorting class which will sort different data
types like int ,float,double,char

User will be given option
Enter the data:
So he can enter any data like {1 234 456 57} or {a d f t b y}
For this i am using template class,now the problem is that how to
create objects of template class based on the data type entered by
user.
For example if user enters data {1 234 456 57} then sort<int> s;
and if user enters data {a d f t b y} then sort<char> s;


One way to decide is we can take sizes of datatypes entered by user and
based on that we can create different objects.

Any other ways we can do that????
 
S

Stephen Howe

User will be given option
Enter the data:
So he can enter any data like {1 234 456 57} or {a d f t b y}
For this i am using template class,now the problem is that how to
create objects of template class based on the data type entered by
user.

How?
Data type is specified at run-time
Template parameters are at compile-time
That is a fundamental mismatch
For example if user enters data {1 234 456 57} then sort<int> s;
and if user enters data {a d f t b y} then sort<char> s;

One way to decide is we can take sizes of datatypes entered by user and
based on that we can create different objects.

Any other ways we can do that????

I did something similar.
I wrote a utility that could sort binary/text files (the OS did not provide
a sort and we did not want a 3rd party utility)
In the interface, you specified keys, their datatypes and this was used by
std::sort().
If the files were too big for some arbitrary memory limit, it would write
temporary intermediate files, sorted and then do a n-way merge.

Google will find you something that does similar

Stephen Howe
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top