Iam creating an apllication using generics in c# that sort the strings as well as integers.Can i use events in that? i mean to say can i fire some event say after the sorting is done or some thing like that?
how to use events in buuble sort application in c#
Collapse
X
-
Tags: None
-
Originally posted by yogeshtiwarijbpIam creating an apllication using generics in c# that sort the strings as well as integers.Can i use events in that? i mean to say can i fire some event say after the sorting is done or some thing like that?Last edited by RedSon; Oct 18 '07, 03:12 PM. -
Originally posted by RedSonSure, you can create an event then signal that event when it completes. You can also use callbacks.Comment
-
Originally posted by yogeshtiwarijbpCan u provide me some example?Comment
-
Originally posted by PlaterWouldn't your code block while the sorting is happening and when it "unblocks" you know the sorting is complete?Comment
-
Originally posted by PlaterWouldn't your code block while the sorting is happening and when it "unblocks" you know the sorting is complete?
This is my code . now can u explain me how i can call events or fire events or raise an event in this code.
plz. help
yogesh
[CODE=cpp]public delegate void Sorting<T>(T[]array) where T:IComparable;
public class SortingGen
{
public static void bubble_sort_gen eric<T>(T[] array) where T : IComparable
{
for (int i = 0; i < (array.Length - 1); i++)
{
for (int j = i + 1; j < (array.Length); j++)
{
if (array[i].CompareTo(arra y[j]) > 0)
{
T temp = array[j];
array[j] = array[i];
array[i] = temp;
}
}
}
}
public static void selectionSortGe neric<T>(T[] a) where T : IComparable
{
for (int sortedSize = 0; sortedSize < a.Length; sortedSize++)
{
int minElementIndex = sortedSize;
T minElementValue = a[sortedSize];
for (int i = sortedSize + 1; i < a.Length; i++)
{
if (a[i].CompareTo(minE lementValue) < 0)
{
minElementIndex = i;
minElementValue = a[i];
}
}
a[minElementIndex] = a[sortedSize];
a[sortedSize] = minElementValue ;
}
}
}
class Class1:SortingG en
{
static void Main(string[] args)
{
System.Console. WriteLine("Ente r 1 for STRING Sort or 2 for NUMERIC Sort");
int num = Convert.ToInt32 (System.Console .ReadLine());
switch (num)
{
case 1:
string[] myArray1 = new string[5];
System.Console. WriteLine("Ente r the elements:");
for (int i = 0; i < 5; i++)
{
myArray1[i] = System.Console. ReadLine();
}
bubble_sort_gen eric(myArray1);
Console.WriteLi ne("After Sorting");
for (int i = 0; i < 5; i++)
{
Console.WriteLi ne(myArray1[i]);
}
Console.ReadLin e();
break;
case 2:
int[] myArray = new int[5];
System.Console. WriteLine("Ente r the elements:");
for (int i = 0; i < 5; i++)
{
myArray[i] = Convert.ToInt32 (System.Console .ReadLine());
}
//Sorting thru Selection Sort
selectionSortGe neric(myArray);
//bubble_sort_gen eric(myArray);
Console.WriteLi ne("After Sorting");
for (int i = 0; i < 5; i++)
{
Console.WriteLi ne(myArray[i]);
}
Console.ReadLin e();
break;
}
}
}
}[/CODE]Comment
-
Please enclose your posted code in [code] tags (See How to Ask a Question).
This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.
Please use [code] tags in future.
Also, you double posted the same response to both my and Plater's response. Doing this is a violation of site policy. Please do not do this again.
MODERATORLast edited by RedSon; Oct 18 '07, 04:11 PM.Comment
-
Originally posted by yogeshtiwarijbpThis is my code . now can u explain me how i can call events or fire events or raise an event in this code.
plz. help
yogeshComment
-
Originally posted by RedSonNo, I am not going to hold your hand or spoon feed your the answer. Read the tutorial that I gave you a link to. After you have read that and tried it out, if you still have questions you can ask again.
I will read the article and try to make things doneComment
-
Originally posted by yogeshtiwarijbpSoory sir
I will read the article and try to make things done
If you have problems with the article, or certain parts don't make sense, you can ask about those parts. But remember no one is going to do your work for you, we will help you do your work on your own.Comment
Comment