wu :: forums (http://www.ocf.berkeley.edu/~wwu/cgi-bin/yabb/YaBB.cgi)
riddles >> general problem-solving / chatting / whatever >> How to write a generic sort in Java/C#?
(Message started by: amichail on Jun 10th, 2007, 8:49am)

Title: How to write a generic sort in Java/C#?
Post by amichail on Jun 10th, 2007, 8:49am
I know how but I am curious as to how many people know how to do this.

Title: Re: How to write a generic sort in Java/C#?
Post by towr on Jun 10th, 2007, 9:09am
I could do it in C++, but I know neither Java nor C# well enough.

Title: Re: How to write a generic sort in Java/C#?
Post by amichail on Jun 10th, 2007, 9:11am
The difficulty with doing this doesn't come up in C++.

Title: Re: How to write a generic sort in Java/C#?
Post by amichail on Jun 14th, 2007, 4:56pm
So no Java/C# programmers here?

You need to use F-bounded polymorphism to solve this problem.

Title: Re: How to write a generic sort in Java/C#?
Post by towr on Jun 15th, 2007, 12:45am

on 06/14/07 at 16:56:53, amichail wrote:
You need to use F-bounded polymorphism to solve this problem.
How is that different from the solution in C++ ?

Title: Re: How to write a generic sort in Java/C#?
Post by amichail on Jun 15th, 2007, 4:56am

on 06/15/07 at 00:45:54, towr wrote:
How is that different from the solution in C++ ?

In Java/C#, you need to specify a constraint on the sorts of types allowed in the array to sort.  For example, you might say that elements of the array must implement the Comparable interface.   But it's more complicated than that.

These sorts of constraints allow you to compile generic code independently of its clients.

On a related note, if you would like to see state of the art language design, try Scala.



Powered by YaBB 1 Gold - SP 1.4!
Forum software copyright © 2000-2004 Yet another Bulletin Board