当前位置: 首页>>代码示例>>C#>>正文


C# ArrayList.BinarySearch方法代码示例

本文整理汇总了C#中ArrayList.BinarySearch方法的典型用法代码示例。如果您正苦于以下问题:C# ArrayList.BinarySearch方法的具体用法?C# ArrayList.BinarySearch怎么用?C# ArrayList.BinarySearch使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ArrayList的用法示例。


在下文中一共展示了ArrayList.BinarySearch方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestStandardArrayList

        public void TestStandardArrayList()
        {
            //
            // Construct array list.
            //
            ArrayList list = new ArrayList();
            // Add items to the lists.
            for (int ii = 0; ii < strHeroes.Length; ++ii)
                list.Add(strHeroes[ii]);

            // Verify items added to list.
            Assert.Equal(strHeroes.Length, list.Count);

            //
            // []  Use BinarySearch to find selected items.
            //
            // Search and verify selected items.
            for (int ii = 0; ii < strFindHeroes.Length; ++ii)
            {
                // Locate item.
                int ndx = list.BinarySearch(strFindHeroes[ii]);
                Assert.True(ndx >= 0);

                // Verify item.
                Assert.Equal(0, strHeroes[ndx].CompareTo(strFindHeroes[ii]));
            }

            // Return Value;
            // The zero-based index of the value in the sorted ArrayList, if value is found; otherwise, a negative number,
            // which is the bitwise complement of the index of the next element.

            list = new ArrayList();
            for (int i = 0; i < 100; i++)
                list.Add(i);
            list.Sort();

            Assert.Equal(100, ~list.BinarySearch(150));

            //[]null - should return -1
            Assert.Equal(-1, list.BinarySearch(null));

            //[]we can add null as a value and then search it!!!
            list.Add(null);
            list.Sort();
            Assert.Equal(0, list.BinarySearch(null));

            //[]duplicate values, always return the first one
            list = new ArrayList();
            for (int i = 0; i < 100; i++)
                list.Add(5);

            list.Sort();
            //remember this is BinarySeearch
            Assert.Equal(49, list.BinarySearch(5));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:55,代码来源:BinarySearchTests.cs

示例2: minStart

    public long minStart(int n, int delta)
    {
        ArrayList parts = new ArrayList();
        long start = 1;
        for (int i = 1; i < 1000000; i++) {
            parts.Add(new Range(start, start + i - 1));
            start += 2 * i;
            if ((long)i >= (long)n*(long)delta)
                break;
        }
        n--;
        Range newRange = new Range(0,0);

        while (n > 0) {
            for (int i = 0; i < parts.Count; i++) {
                Range range = (Range)parts[i];
                newRange.start = range.start + delta;
                newRange.end = range.end + delta;
                int index = parts.BinarySearch(i, parts.Count - i, newRange, null);
                if (index < 0)
                    range.valid = false;
                else {
                    Range otherRange = (Range)parts[index];
                    if (range.end + delta <= otherRange.end) {
                        long diff = range.end + delta - otherRange.start + 1;
                        if (diff < range.length) {
                            range.start = range.end - diff + 1;
                        }
                    }
                    else if (range.start + delta >= otherRange.start) {
                        long diff = otherRange.end - range.start - delta + 1;
                        if (diff < range.length) {
                            range.end = range.start + diff - 1;
                        }
                    }
                }
            }
            ArrayList temp = parts;
            parts = new ArrayList();
            for (int i = 0; i < temp.Count; i++) {
                if (((Range)temp[i]).valid)
                    parts.Add(temp[i]);
            }
            n--;
        }
        for (int i = 0; i < parts.Count; i++) {
            Range range = (Range)parts[i];
            if (!range.valid)
                continue;
            return (range.start);
        }

        return -1;
    }
开发者ID:Tilps,项目名称:Stash,代码行数:54,代码来源:Program.cs

示例3: runTest

 public bool runTest()
   {
   int iCountErrors = 0;
   int iCountTestcases = 0;
   String strLoc="123_er";
   String strInfo = null;
   Console.Out.Write( s_strClassMethod );
   Console.Out.Write( ": " );
   Console.Out.Write( s_strTFPath + s_strTFName );
   Console.Out.Write( ": " );
   Console.Out.Write( s_strDtTmVer );
   Console.Out.WriteLine( " runTest started..." );
   Object o1;
   Char chValue;
   Int16 i16Value;
   int iReturnValue;
   Object[,] o2ArrValues;
   ArrayList lst1;
   try
     {
     LABEL_860_GENERAL:
     do
       {
       strLoc="536df";
       lst1 = new ArrayList( (cArr) );
       lst1.Sort();
       if ( cArr.Length != lst1.Count)
	 {
	 ++iCountErrors;
	 Console.WriteLine( s_strTFAbbrev + ", Err_623sd! cArr.Length==" + cArr.Length);
	 }
       ++iCountTestcases;
       for(int i=0; i<cArr.Length; i++)
	 {
	 chValue = cArr[i];
	 if ( lst1.BinarySearch(0, lst1.Count, chValue, null) < 0 )
	   {
	   ++iCountErrors;
	   Console.WriteLine( s_strTFAbbrev + "Err_320ye_" + i + " chValue==" + chValue);
	   }
	 }
       } while ( false );
     }
   catch (Exception exc_general)
     {
     ++iCountErrors;
     Console.WriteLine( s_strTFAbbrev + "Error Err_8888yyy!  strLoc=="+ strLoc +" ,exc_general=="+ exc_general );
     }
   if ( iCountErrors == 0 ) {   return true; }
   else {  return false;}
   }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:51,代码来源:co3777aslist.cs

示例4: SupprimerTOUS

    static void SupprimerTOUS(ArrayList pers, string nomRecherche)
    {
        WorldCup aChercher = new WorldCup(nomRecherche, ' ', 0.0, 0.0, 0);

        int indice = 123456, rang = 0;

        while (indice >= 0)
        {
            indice = pers.BinarySearch(aChercher);
            Console.WriteLine(indice);
            if (indice >= 0)
            {
                Console.WriteLine("{0, 2:D}) {1}", ++rang, pers[indice]);
                pers.RemoveAt(indice);
            }
        }
        if (rang > 0)
            Console.WriteLine("On a supprime {0} WorldCup(s)", rang);
        else
            Console.WriteLine("On ne trouve pas:\n" + aChercher);

        Console.WriteLine();
    }
开发者ID:dsj312,项目名称:DSJD,代码行数:23,代码来源:ArrayList2.cs

示例5: TestArrayListWrappers

        public void TestArrayListWrappers()
        {
            //
            // Construct array list.
            //
            ArrayList arrList = new ArrayList();

            // Add items to the lists.
            for (int ii = 0; ii < strHeroes.Length; ++ii)
            {
                arrList.Add(strHeroes[ii]);
            }

            // Verify items added to list.
            Assert.Equal(strHeroes.Length, arrList.Count);

            //Adapter, GetRange, Synchronized, ReadOnly returns a slightly different version of 
            //BinarySearch, Following variable cotains each one of these types of array lists

            ArrayList[] arrayListTypes = {
                                    arrList,
                                    ArrayList.Adapter(arrList),
                                    ArrayList.FixedSize(arrList),
                                    arrList.GetRange(0, arrList.Count),
                                    ArrayList.ReadOnly(arrList),
                                    ArrayList.Synchronized(arrList)};

            int ndx = 0;
            foreach (ArrayList arrayListType in arrayListTypes)
            {
                arrList = arrayListType;

                //
                // []  Use BinarySearch to find selected items.
                //
                // Search and verify selected items.
                for (int ii = 0; ii < strFindHeroes.Length; ++ii)
                {
                    // Locate item.
                    ndx = arrList.BinarySearch(0, arrList.Count, strFindHeroes[ii], this);
                    Assert.True(ndx >= 0);

                    // Verify item.
                    Assert.Equal(0, strHeroes[ndx].CompareTo(strFindHeroes[ii]));
                }

                //
                // []  Locate item in list using null comparer.
                //
                ndx = arrList.BinarySearch(0, arrList.Count, "Batman", null);
                Assert.Equal(2, ndx);

                //
                // []  Locate insertion index of new list item.
                //
                // Append the list.
                ndx = arrList.BinarySearch(0, arrList.Count, "Batgirl", this);
                Assert.Equal(2, ~ndx);

                //
                // []  Bogus Arguments
                //
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-100, 1000, arrList.Count, this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-100, 1000, "Batman", this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(-1, arrList.Count, "Batman", this));
                Assert.Throws<ArgumentOutOfRangeException>(() => arrList.BinarySearch(0, -1, "Batman", this));

                Assert.Throws<ArgumentException>(() => arrList.BinarySearch(1, arrList.Count, "Batman", this));
                Assert.Throws<ArgumentException>(() => arrList.BinarySearch(3, arrList.Count - 2, "Batman", this));
            }
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:71,代码来源:BinarySearchTests.cs

示例6: CompareObjects


//.........这里部分代码省略.........
     if(!ilst1.IsSynchronized)
         hsh1["Synchronized"] = "Not";
     if(good.Count == bad.Count)
     {
         if(fVerbose)
             Console.WriteLine("ToArray()");
         Object[] oArr1 = good.ToArray();
         Object[] oArr2 = bad.ToArray();
         for(int i=0; i<good.Count; i++)
         {
             if((Int32)oArr1[i] != (Int32)oArr2[i])
                 hsh1["ToArray"] = "()";
         }
         iArr1 = (Int32[])good.ToArray(typeof(Int32));
         iArr2 = (Int32[])bad.ToArray(typeof(Int32));
         for(int i=0; i<good.Count; i++)
         {
             if(iArr1[i] != iArr2[i])
                 hsh1["ToArray"] = "(Type)";
         }
     }
     if(fVerbose)
         Console.WriteLine("Capacity()");
     if(good.Capacity != bad.Capacity)
     {
         hsh1["Capacity"] = "get";
     }
     if(!hsh1.ContainsKey("IsReadOnly"))
     {
         good.Clear();
         for(int i=100; i>0; i--)
             good.Add(i);
         if(fVerbose)
             Console.WriteLine("Sort() & BinarySearch()");
         bad.Sort();
         for(int i=0; i<bad.Count-1; i++)
         {
             if((Int32)bad[i] > (Int32)bad[i+1])
                 hsh1["Sort"] = "()";
         }			
         for(int i=0; i<bad.Count; i++)
         {
             if(bad.BinarySearch(bad[i]) != i)
                 hsh1["BinarySearch"] = "(Object)";
         }
         bad.Reverse();
         if(bad.Count>0)
         {
             for(int i=0; i<99; i++)
             {
                 if((Int32)bad[i] < (Int32)bad[i+1])
                     hsh1["Reverse"] = "()";
             }
             good.Clear();
             for(int i=100; i>0; i--)
                 good.Add(i.ToString());
         }
         good.Clear();
         for(int i=90; i>64; i--)
             good.Add(((Char)i).ToString());
         try
         {
             bad.Sort(new CaseInsensitiveComparer());
             if(bad.Count>0)
             {
                 for(int i=0; i<(bad.Count-1); i++)
开发者ID:ArildF,项目名称:masters,代码行数:67,代码来源:co3966wrappertests.cs

示例7: runTest

 public virtual bool runTest()
 {
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Console.Error.WriteLine( strName + ": " + strTest + " runTest started..." );
     ArrayList arrList = null;
     String [] strHeroes =
         {
             "Aquaman",
             "Atom",
             "Batman",
             "Black Canary",
             "Captain America",
             "Captain Atom",
             "Catwoman",
             "Cyborg",
             "Flash",
             "Green Arrow",
             "Green Lantern",
             "Hawkman",
             "Huntress",
             "Ironman",
             "Nightwing",
             "Robin",
             "SpiderMan",
             "Steel",
             "Superman",
             "Thor",
             "Wildcat",
             "Wonder Woman",
     };
     String [] strFindHeroes =
         {
             "Batman",
             "Superman",
             "SpiderMan",
             "Wonder Woman",
             "Green Lantern",
             "Flash",
             "Steel"
         };
     do
     {
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Construct ArrayList" );
         try
         {
             arrList = new ArrayList();
             if ( arrList == null )
             {
                 Console.WriteLine( strTest+ "E_101: Failed to construct new ArrayList" );
                 ++iCountErrors;
                 break;
             }
             for ( int ii = 0; ii < strHeroes.Length; ++ii )
             {
                 arrList.Add( strHeroes[ii] );
             }
             if ( arrList.Count != strHeroes.Length )
             {
                 String strInfo = strTest + " error: ";
                 strInfo = strInfo + "Expected size <"+ strHeroes.Length + "> ";
                 strInfo = strInfo + "Returned size <"+ arrList.Count + "> ";
                 Console.WriteLine( strTest+ "E_202: " + strInfo );
                 ++iCountErrors;
                 break;
             }
         }
         catch (Exception ex)
         {
             Console.WriteLine( strTest+ "E_10001: Unexpected Exception: " + ex.ToString() );
             ++iCountErrors;
             break;
         }
         ++iCountTestcases;
         Console.Error.WriteLine( "[]  Use BinarySearch to find selected items" );
         try
         {
             for ( int ii = 0; ii < strFindHeroes.Length; ++ii )
             {
                 int ndx = arrList.BinarySearch( 0, arrList.Count, strFindHeroes[ii], this );
                 if ( ndx >= strHeroes.Length )
                 {
                     String strInfo = strTest + " error: ";
                     strInfo = strInfo + "Returned index <"+ ndx + "> out of range";
                     Console.WriteLine( strTest+ "E_303: " + strInfo );
                     ++iCountErrors;
                     break;
                 }
                 if ( strHeroes[ndx].CompareTo( strFindHeroes[ii] ) != 0 )
                 {
                     String strInfo = strTest + " error: ";
                     strInfo = strInfo + "Expected index of hero <"+ strFindHeroes[ii] + "> ";
                     strInfo = strInfo + "Returned index of hero <"+ strHeroes[ndx] + "> ";
                     Console.WriteLine( strTest+ "E_404: " + strInfo );
                     ++iCountErrors;
                     break;
                 }
             }
         }
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co2460binarysearch_iioi.cs

示例8: runTest

 public virtual bool runTest()
 {
     int iCountErrors = 0;
     int iCountTestcases = 0;
     Console.Error.WriteLine( s_strClassMethod + ": " + s_strTFName + " runTest started..." );
     ArrayList list = null;
     String strLoc = "Loc_000oo";
     String [] strHeroes =
         {
             "Aquaman",
             "Atom",
             "Batman",
             "Black Canary",
             "Captain America",
             "Captain Atom",
             "Catwoman",
             "Cyborg",
             "Flash",
             "Green Arrow",
             "Green Lantern",
             "Hawkman",
             "Huntress",
             "Ironman",
             "Nightwing",
             "Robin",
             "SpiderMan",
             "Steel",
             "Superman",
             "Thor",
             "Wildcat",
             "Wonder Woman",
     };
     String [] strFindHeroes =
         {
             "Batman",
             "Superman",
             "SpiderMan",
             "Wonder Woman",
             "Green Lantern",
             "Flash",
             "Steel"
         };
     try 
     {
         strLoc = "Loc_001o1";
         ++iCountTestcases;
         try
         {
             list = new ArrayList();
             if ( list == null )
             {
                 Console.WriteLine( s_strTFName+ "E_101: Failed to construct new ArrayList" );
                 ++iCountErrors;
             }
             for ( int ii = 0; ii < strHeroes.Length; ++ii )
                 list.Add( strHeroes[ii] );
             if ( list.Count != strHeroes.Length )
             {
                 Console.WriteLine( "E_202: ");
                 ++iCountErrors;
             }
         }
         catch (Exception ex)
         {
             ++iCountErrors;
             Console.WriteLine( s_strTFName+ "E_10001: Unexpected Exception: " + ex.ToString() );
         }
         ++iCountTestcases;
         try
         {
             for ( int ii = 0; ii < strFindHeroes.Length; ++ii )
             {
                 int ndx = list.BinarySearch(strFindHeroes[ii]);
                 if ( ndx >= strHeroes.Length )
                 {
                     ++iCountErrors;
                     Console.WriteLine( "Err_753fg unexpected value returned" );
                 }
                 if ( strHeroes[ndx].CompareTo( strFindHeroes[ii] ) != 0 )
                 {
                     ++iCountErrors;
                     Console.WriteLine( "Err_853deg! unexpected value returned");
                 }
             }
         }
         catch (Exception ex)
         {
             ++iCountErrors;
             Console.WriteLine( s_strTFName+ "E_10002: Unexpected Exception: " + ex.ToString() );
         }
         strLoc = "Loc_00437sg";
         iCountTestcases++;
         list = new ArrayList();
         for(int i=0; i<100; i++)
             list.Add(i);
         list.Sort();
         if(~list.BinarySearch(150)!= 100)
         {
             iCountErrors++;
             Console.WriteLine( "Err_7853rg! wrong value returned, " + list.BinarySearch(150) );
//.........这里部分代码省略.........
开发者ID:ArildF,项目名称:masters,代码行数:101,代码来源:co8597binarysearch_obj.cs

示例9: CompareObjects


//.........这里部分代码省略.........

            //ToArray(type)
            iArr1 = (int[])good.ToArray(typeof(int));
            iArr2 = (int[])bad.ToArray(typeof(int));
            for (int i = 0; i < good.Count; i++)
            {
                if (iArr1[i] != iArr2[i])
                    hsh1["ToArray"] = "(Type)";
            }
        }

        //Capacity - get
        if (good.Capacity != bad.Capacity)
        {
            hsh1["Capacity"] = "get";
        }

        //Fixed size methods
        if (!hsh1.ContainsKey("IsReadOnly"))
        {
            good.Clear();
            for (int i = 100; i > 0; i--)
                good.Add(i);
            //Sort() & BinarySearch(Object)
            bad.Sort();
            for (int i = 0; i < bad.Count - 1; i++)
            {
                if ((int)bad[i] > (int)bad[i + 1])
                    hsh1["Sort"] = "()";
            }

            for (int i = 0; i < bad.Count; i++)
            {
                if (bad.BinarySearch(bad[i]) != i)
                    hsh1["BinarySearch"] = "(Object)";
            }

            //Reverse()
            bad.Reverse();
            if (bad.Count > 0)
            {
                for (int i = 0; i < 99; i++)
                {
                    if ((int)bad[i] < (int)bad[i + 1])
                        hsh1["Reverse"] = "()";
                }

                good.Clear();
                for (int i = 100; i > 0; i--)
                    good.Add(i.ToString());
            }

            good.Clear();
            for (int i = 90; i > 64; i--)
                good.Add(((Char)i).ToString());

            try
            {
                bad.Sort(new CaseInsensitiveComparer());
                if (bad.Count > 0)
                {
                    for (int i = 0; i < (bad.Count - 1); i++)
                    {
                        if (((String)bad[i]).CompareTo(((String)bad[i + 1])) >= 0)
                            hsh1["Sort"] = "(IComparer)";
                    }
开发者ID:noahfalk,项目名称:corefx,代码行数:67,代码来源:WrapperTests.cs

示例10: Inserer

    static void Inserer(ArrayList pers, string nom, char sexe, double taille,
        double poids, int numero)
    {
        nom = nom.ToUpper();
        for (int i = nom.Length; i < 30; i++) nom += " ";

        WorldCup aAjouter = new WorldCup(nom, sexe, taille, poids, numero);

        int indice = pers.BinarySearch(aAjouter);
        if (indice < 0)
            indice = (-indice) - 1;
        pers.Insert(indice, aAjouter);
    }
开发者ID:dsj312,项目名称:DSJD,代码行数:13,代码来源:ArrayList2.cs

示例11: Inserer

//---------------------------------------------------------------------5.Ajouter
    static void Inserer(ArrayList paysInscrits, char groupe, int continent,
    string pays, string capitale, int superficie, int population)
    {
        pays = pays.ToUpper();
        pays = pays.ToUpper();

        for (int i = pays.Length; i < 34; i++) pays += " ";
        
        for (int i = capitale.Length; i < 9; i++) capitale += " ";

        WorldCup aAjouter = new WorldCup(groupe, continent, pays, capitale,
            superficie, population);

        int indice = paysInscrits.BinarySearch(aAjouter);
        if (indice < 0)
            indice = (-indice) - 1;
        paysInscrits.Insert(indice, aAjouter);
        
        Console.WriteLine("Nous avons ajouté le pays :\n {1}) {0}\n",
        aAjouter, indice);
    }
开发者ID:dsj312,项目名称:DSJD,代码行数:22,代码来源:3b.cs

示例12: forwardSend_Click

    protected void forwardSend_Click(object sender, EventArgs e)
    {
        SortedList noPrivilegeList = new SortedList();
        SortedList noEmailAddressList = new SortedList();
        SortedList wrongEmailAddressList = new SortedList();
        ArrayList allExternalUsers = new ArrayList();

        ISubjectFetchProvider subjectProvider = (new SubjectProviderFactory()).GetSubjectFetchProvider();
        ArrayList userList = new ArrayList();
        IList users = new ArrayList();
        const string MatchEmailPattern =
            @"^(([\w-]+\.)+[\w-]+|([a-zA-Z]{1}|[\w-]{2,}))@"
           + @"((([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\."
           + @"([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])\.([0-1]?[0-9]{1,2}|25[0-5]|2[0-4][0-9])){1}|"
           + @"([a-zA-Z]+[\w-]+\.)+[a-zA-Z]{2,4})$";

        try
        {
            StringBuilder mailtoUsers = new StringBuilder();
            MailToUser[] jsonObjectArray = WebUtility.DeserializeAjaxResult("[" + hideMailto.Value + "]", typeof(MailToUser[])) as MailToUser[];
            String[] externalUsers = this.txtMailto.Value.Trim().Split(';'); //外部收件者
            foreach (string emailAddress in externalUsers)
            {
                if (externalUsers.Length==0)
                {
                    break;
                }
                string address = emailAddress.Trim();

                if (address.Length == 0)
                {
                    noEmailAddressList.Add(address, address);
                }
                else
                {
                    if (Regex.IsMatch(address, MatchEmailPattern))
                    {
                        if (allExternalUsers.BinarySearch(address) < 0)
                        {
                            allExternalUsers.Add(address);
                        }
                    }
                    else
                    {
                        wrongEmailAddressList.Add(address, address);
                    }
                }
            }

            foreach (MailToUser mailtoUser in jsonObjectArray)
            {
                users.Clear();
                switch (Convert.ToInt32(mailtoUser.SubjectType))
                {
                    case 0:
                        if (!string.IsNullOrEmpty(mailtoUser.EmailAddress))
                        {
                            if (Regex.IsMatch(mailtoUser.EmailAddress, MatchEmailPattern))
                            {
                                userList.Add(mailtoUser);
                            }
                            else
                            {
                                wrongEmailAddressList.Add(mailtoUser.SubjectId, mailtoUser.DisplayName);
                            }
                        }
                        else
                        {
                            noEmailAddressList.Add(mailtoUser.SubjectId, mailtoUser.DisplayName);
                        }
                        break;
                    case 1:
                        users = subjectProvider.GetUsersInOU(mailtoUser.SubjectId);
                        break;
                    case 2:
                        users = subjectProvider.GetUsersInGroup(mailtoUser.SubjectId);
                        break;
                    case 3:
                        users = subjectProvider.GetUsersInRole(mailtoUser.SubjectId);
                        break;
                    default:
                        break;
                }

                if (users != null && users.Count > 0)
                {
                    foreach (User user in users)
                    {
                        if (!string.IsNullOrEmpty(user.EmailAddress))
                        {
                            if (Regex.IsMatch(user.EmailAddress, MatchEmailPattern))
                            {
                                userList.Add(ConvertUserToMailToUser(user));
                            }
                            else
                            {
                                wrongEmailAddressList.Add(user.SubjectId, user.DisplayName);
                            }
                        }
                        else
//.........这里部分代码省略.........
开发者ID:gofighting123,项目名称:test,代码行数:101,代码来源:readdocument.aspx.cs

示例13: GetData

 /// <summary>
 /// Retrieves the data in a list mapped by a key.
 /// Returns null if no such data exists.
 /// </summary>
 /// <param name="list">The sorted list to check.</param>
 /// <param name="key">The data to map with.</param>
 /// <param name="comparator">IComparer object for sorting.</param>
 protected internal static object GetData(ArrayList list, object key, IComparer comparator)
 {
     int ind;
     string s = key as string;
     if (s != null)
     {
         s = s.NormalizeWhiteSpaces();
         ind = list.BinarySearch(s, comparator);
     }
     else
     {
         ind = list.BinarySearch(key, comparator);
     }
     if (ind < 0) return null;
     return list[ind];
 }
开发者ID:Hikari9,项目名称:ScheduleMaster,代码行数:23,代码来源:Classes.cs

示例14: Main


//.........这里部分代码省略.........
            Console.WriteLine("Value of 100 was found at at location = {0}", location);

        Console.WriteLine("\n\n");

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', ""); //Display random data
        QuickSort(ref xdata);
        Console.WriteLine("Using BINARY SEARCH ALGORITHM to look for 4th data entry in randomized list");

        location = BinSearch(ref xdata, xdata[4]);
        if (location == -1)
            Console.WriteLine("Value was not found in list");
        else
            Console.WriteLine("Found it at location = {0}", location);

        location = InterpolationSearch(ref xdata, 100);
        if (location == -1)
            Console.WriteLine("Value of 100 was not found in list");
        else
            Console.WriteLine("Value of 100 was found at at location = {0}", location);

        Console.WriteLine("\n\n");

        //The ArrayList collection in C# comes with its own built-in search algorithm.
        //And can be called up to perform a search as shown below.

        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");    //Display random data
        Console.WriteLine("Using the built-in BINARY SEARCH ALGORITHM in ArrayList data structure");
        ArrayList alist = new ArrayList();      //Set up an ArrayList object
        for (int i = 0; i < xdata.Length; i++)
            alist.Add(xdata[i]);                //and add some radomized data to it

        location = alist.BinarySearch(xdata[4]); //Call up its BinarySearch method
        if (location == -1)                     //and run the examples
            Console.WriteLine("Value was not found in list");
        else
            Console.WriteLine("Found it at location = {0}", location);

        location = alist.BinarySearch(100);
        if (location < 0)
            Console.WriteLine("Value was not found in list");
        else
            Console.WriteLine("Found it at location = {0}", location);


        Console.WriteLine("Testing to find the n-th largest value in a random array\n\nOriginal Data (method 1): \n");
        MixDataUp(ref xdata, rdn);
        DisplayElements(ref xdata, 'b', "");

        int nthMathIndex1 = 8;

        int nthMaxValue1 = NthLargest1(xdata, nthMathIndex1);

        Console.WriteLine("\nThe " + nthMathIndex1 + " largest value in the array above is: " + nthMaxValue1 + "\n");

        Console.WriteLine("Verifying result... \nFirst verify that original data array is not changed.\n");
        DisplayElements(ref xdata, 'b', "");
        Console.WriteLine("\nThen sort the array and count the requested position from the largest value at the top\n");
        QuickSort(ref xdata);
        DisplayElements(ref xdata, 'a', "QuickSort");

        //////

        Console.WriteLine("\n\nTesting to find the n-th largest value in a random array\n\nOriginal Data (method 2): \n");
        MixDataUp(ref xdata, rdn);
开发者ID:rishabhverma17,项目名称:Codes,代码行数:67,代码来源:Program.cs


注:本文中的ArrayList.BinarySearch方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。