Chaitanya

Chaitanya

  • NA
  • 58
  • 57.4k

How to find out whether the list contains missing elements or not

Sep 9 2011 11:04 AM
I am having a requirement like to find out the missing numbers in the list available. I implemented a code but i am unable to get for some of the sequences.

Suppose if i have my list elements as 1,3 i would like to return this as false as 2 is missing.

If i have 1,2,3 i would like to return true as it is in sequence.

Like that i have random numbers in my list so can any one give me the logic for this

I tried this but for some conditions it is not working

int iMax = 0;
        int iMin = 0;

        iMin = (int)lstSequence[0];

        for (int iLoop = 0; iLoop < lstSequence.Count; iLoop++)
        {
            iMax = (int)lstSequence[iLoop];
        }

        for (int icompare = iMin; icompare <= iMax; icompare++)
        {
            if (icompare == iMin || icompare == iMax)
            {
            }
            else
            {
                if (lstSequence.Contains(icompare))
                {
                    seq_flag = true;
                }
                else
                {
                    seq_flag = false;
                }
            }
        }

Answers (2)