lundi 9 mai 2016

Inserting data into tables by comparing

I am using the tables to store subject names of one section of a course. My question is, how can I go about inserting the subject names from one table to another table in such a way that no two subjects can occur at the same hour.

Example :

Table-1

Hour     Subject-name

1           C#
2           Java
3           OS
4           C++
5           DBMS

I need to enter the same set of values to another table say, table-2 in such a way :

Table-2

Hour            Subject-name

1                OS
2                DBMS
3                C#
4                Java
5                C++

I have used to shuffle operation for a list in order to shuffle the elements randomly. But, there is a possibility of occurrence of the same subject twice.

public static void Shuffle<T>(IList<T> list)
{
    int n = list.Count;
    while (n > 1)
    {
        n--;
        int k = rng.Next(n + 1);
        T value = list[k];
        list[k] = list[n];
        list[n] = value;
    }
}




Aucun commentaire:

Enregistrer un commentaire