public delegate bool FunctieCompara(int a, int b); this is the delegate
Simple function calls:
TyG.bubbleSort(TyG.max, TyG.Lungime, TyG.Secv);
TyG.bubbleSort(TyG.min, TyG.Lungime, TyG.secvMin);
I have a Class Sorts and in this class I have a lot of methods like
public void bubbleSort(functionDelegate f, int n, int [] v)
and much more sorts but with this parameters. In other class I have a instance of
Sortst tyg = new Sorts()
I want to create a thread
Thread Thr = new Thread(new ThreadStart(tyg.bubbleSort(functionDelegate)))
I didn’t figure it out this thing works in my case, how can i use thread with a method that use a delegate, in my case the delegate is a max/min for comparing numbers for doing sorts in place in v[]. I want to make 2 threads for doing the both sorts bubbleSort(max, n, v) and bubbleSort(min, n, v) same time. That is what thread does anyway, anyhow can anyone help me a little please?
Do you mean like this?
Note that if you are sorting in place you should use different arrays (
v1andv2) because otherwise the threads will be overwriting the same array.If you are interested, also look over the
Taskconstruct of .NET 4.0.Alternatively, if you want to be cool (.NET 4.0+):