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


C# SortedList.Remove方法代码示例

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


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

示例1: ContainsNearbyAlmostDuplicate

    public bool ContainsNearbyAlmostDuplicate(int[] nums, int k, int t)
    {

        if (k <= 0 || t < 0) return false;
        var index = new SortedList<int, object>();
        for (int i = 0; i < nums.Length; ++i)
        {
            if (index.ContainsKey(nums[i]))
            {
                return true;
            }
            index.Add(nums[i], null);
            var j = index.IndexOfKey(nums[i]);
            if (j > 0 && (long)nums[i] - index.Keys[j - 1] <= t)
            {
                return true;
            }
            if (j < index.Count - 1 && (long)index.Keys[j + 1] - nums[i] <= t)
            {
                return true;
            }
            if (index.Count > k)
            {
                index.Remove(nums[i - k]);
            }
        }
        return false;
    }
开发者ID:alexguo88,项目名称:LeetCode,代码行数:28,代码来源:220.ContainsDuplicateIII.cs

示例2: TestMethod

 public void TestMethod(int operationCount)
 {
     var stack = new Stack<int>();
     var heap = new SortedList<int, int>();
     var minStack = new MinStack();
     Repeat(operationCount, () =>
     {
         var operation = stack.Count == 0 ? 0 : Random.Next(4);
         var x = Random.Next(int.MaxValue);
         switch (operation)
         {
             case 0: // Push
                 stack.Push(x);
                 heap.Add(x, x);
                 minStack.Push(x);
                 break;
             case 1: // Pop
                 heap.Remove(stack.Peek());
                 stack.Pop();
                 minStack.Pop();
                 break;
             case 2: // Top
                 Assert.AreEqual(stack.Peek(), minStack.Top());
                 break;
             case 3: // GetMin
                 Assert.AreEqual(heap.First().Key, minStack.GetMin());
                 break;
         }
     });
 }
开发者ID:alexguo88,项目名称:LeetCode,代码行数:30,代码来源:155.MinStack.Test.cs

示例3: runTest

 public bool runTest()
 {
     Console.WriteLine(s_strTFPath + " " + s_strTFName + " , for " + s_strClassMethod + " , Source ver : " + s_strDtTmVer);
     int iCountErrors = 0;
     int iCountTestcases = 0;
     String strLoc = "Loc_000oo";
     String strValue;
     SortedList dic1;
     try 
     {
         do
         {
             strLoc = "Loc_8345vdfv";
             dic1 = new SortedList();
             for(int i=0; i<10; i++)
             {
                 strValue = "String_" + i;
                 dic1.Add(i, strValue);
             }
             iCountTestcases++;
             for(int i=0; i<10; i++)
             {
                 if(!dic1.Contains(i)) 
                 {
                     iCountErrors++;
                     Console.WriteLine("Err_561dvs_" + i + "! Expected value not returned, " + dic1.Contains(i));
                 }
             }
             iCountTestcases++;
             if(dic1.IsReadOnly) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_65323gdfgb! Expected value not returned, " + dic1.IsReadOnly);
             }
             dic1.Remove(0);
             iCountTestcases++;
             if(dic1.Contains(0)) 
             {
                 iCountErrors++;
                 Console.WriteLine("Err_65323gdfgb! Expected value not returned, " + dic1.Contains(0));
             }
         } while (false);
     } 
     catch (Exception exc_general ) 
     {
         ++iCountErrors;
         Console.WriteLine (s_strTFAbbrev + " : Error Err_8888yyy!  strLoc=="+ strLoc +", exc_general==\n"+exc_general.ToString());
     }
     if ( iCountErrors == 0 )
     {
         Console.WriteLine( "paSs.   "+s_strTFPath +" "+s_strTFName+" ,iCountTestcases=="+iCountTestcases);
         return true;
     }
     else
     {
         Console.WriteLine("FAiL!   "+s_strTFPath+" "+s_strTFName+" ,iCountErrors=="+iCountErrors+" , BugNums?: "+s_strActiveBugNums );
         return false;
     }
 }
开发者ID:ArildF,项目名称:masters,代码行数:59,代码来源:co3916get_isreadonly.cs

示例4: KeyboardInput

 public virtual void KeyboardInput(SortedList<eBindings, BindInfo> binds)
 {
     if (binds.ContainsKey(eBindings.UI_Exit))
     {
         if (m_bCanExit) { GameState.Get().PopUI(); }
         binds.Remove(eBindings.UI_Exit);
     }
 }
开发者ID:nagyistoce,项目名称:return-of-the-trojans,代码行数:8,代码来源:UIScreen.cs

示例5: AddOneDeleteOne

		public void AddOneDeleteOne()
		{
			SortedList<int,string> t = new SortedList<int,string>();
			t.Add(1, "one");
			t.Remove(1);
			Assert.AreEqual("" ,Dump(t));
			Assert.IsTrue(t.Count == 0);
		}
开发者ID:relaxar,项目名称:reko,代码行数:8,代码来源:SortedListExTests.cs

示例6: Simple

        public void Simple()
        {
            var sortedList = new SortedList<int>();

            for (var i = 50; i >= 0; i--)
            {
                sortedList.Add(i * 2);
            }

            Assert.AreEqual(sortedList.Count, 51);

            Assert.IsTrue(sortedList.Remove(50));
            Assert.AreEqual(sortedList.Count, 50);

            Assert.IsFalse(sortedList.Remove(3));
            Assert.AreEqual(sortedList.Count, 50);
        }
开发者ID:havok,项目名称:ngenerics,代码行数:17,代码来源:Remove.cs

示例7: KeyboardInput

        public override void KeyboardInput(SortedList<eBindings, BindInfo> binds)
        {
            GameState g = GameState.Get();
            if (binds.ContainsKey(eBindings.UI_Exit))
            {
                g.ShowPauseMenu();
                binds.Remove(eBindings.UI_Exit);
            }

            // Handle any input before the gameplay screen can look at it

            base.KeyboardInput(binds);
        }
开发者ID:nagyistoce,项目名称:flightsim,代码行数:13,代码来源:UIGameplay.cs

示例8: deleteMessage

        public static void deleteMessage(SortedList<int, Mail> deleteMessage)
        {
            Console.WriteLine("Write the number of the mail to delete it");
            string deleteMail = Console.ReadLine();
            try
            {
                int useDelete = Int32.Parse(deleteMail);
                deleteMessage.Remove(useDelete);
            }
            catch (FormatException)
            {
                
            }

        }
开发者ID:JosefineRutgerson,项目名称:Email-Client-Console,代码行数:15,代码来源:ConfigMessageList.cs

示例9: knockOutPermutations

        /// <summary>
        /// This function knocks out a character from the dictionary characterCounts and then computes the permutations on the remnant.
        /// </summary>
        /// <param name="knockOutCharacter">The character to be removed from the dictionary characterCounts.</param>
        /// <param name="characterCounts">A dictionary which contains letters as keys and their occurences as values.</param>
        /// <returns>The total number permutations possible without knockOutCharacter.</returns>
        public static UInt64 knockOutPermutations(char knockOutCharacter, SortedList<char, UInt64> characterCounts)
        {
            //Create a copy of the dictionary characterCounts because it is passed by reference.
            SortedList<char, UInt64> knockOutCcharacterCounts = new SortedList<char, UInt64>(characterCounts);

            //Remove knockOutCharacter if possible.
            if (characterCounts.ContainsKey(knockOutCharacter) && knockOutCcharacterCounts[knockOutCharacter] > 1)
            {
                knockOutCcharacterCounts[knockOutCharacter] -= 1;
            }
            else if (characterCounts.ContainsKey(knockOutCharacter) && knockOutCcharacterCounts[knockOutCharacter] == 1)
            {
                knockOutCcharacterCounts.Remove(knockOutCharacter);
            }
            return Program.permutations(knockOutCcharacterCounts);
        }
开发者ID:28ACB29,项目名称:Word-Ranker,代码行数:22,代码来源:Program.cs

示例10: GetTransforms

    /// <summary>
    /// Returns children transforms, sorted by name.
    /// </summary>
    Transform[] GetTransforms()
    {
        if (SplineRoot != null)
        {
            SortedList mySL = new SortedList();

            foreach (Transform child in SplineRoot.transform)
                mySL.Add(child.name, child);

            mySL.Remove(SplineRoot.transform.name);
            Transform[] ret = new Transform[mySL.Count];
            for (int i=0;i<mySL.Count;i++)
                ret[i] = (Transform)mySL.GetByIndex(i);

            return ret;
        }

        return null;
    }
开发者ID:BBJV,项目名称:camachi,代码行数:22,代码来源:SplineController.cs

示例11: UseOfSortedList

        public void UseOfSortedList() { 
            //SortedList is eigenlijk een sorted dictionary...
            SortedList<string, Werknemer> werknemers = new SortedList<string, Werknemer>();
            Werknemer piet = new Werknemer() { Voornaam="Piet", Achternaam="Pietersen"};
            Werknemer jan = new Werknemer() { Voornaam="Jan", Achternaam="Jansen"};
            Werknemer peter = new Werknemer() { Voornaam="Peter", Achternaam="Petersen"};
            Werknemer marieke = new Werknemer() { Voornaam="Marieke", Achternaam="Mariekersen"};

            werknemers.Add("PietKey", piet);
            werknemers.Add("JanKey", jan);
            werknemers.Add("PeterKey", peter);
            werknemers.Add("MariekeKey", marieke);

            werknemers.Remove("JanKey");

            foreach (string key in werknemers.Keys)
            {
                Debug.WriteLine(werknemers[key].Volledigenaam());
            }

        
        }
开发者ID:ThijsvanHout,项目名称:Test-Github-zoveel,代码行数:22,代码来源:Collections.cs

示例12: sendWork

        /// <summary>
        /// Send a work to a client
        /// </summary>
        /// <param name="listClient">List of clients</param>
        /// <param name="listPacketSended">Packet already sended</param>
        /// <param name="ipAddress">Ip address of a client</param>
        /// <param name="port">Port of a client</param>
        /// <param name="nbrPackets">Number packet to send</param>
        /// <param name="issueNumber">Issu number</param>
        public void sendWork(ref SortedList<string, Client> listClient, ref SortedList<int, PacketInfo>listPacketSended, string ipAddress, int port, int nbrPackets,int issueNumber)
        {
            List<byte[]> listWorksToSend = new List<byte[]>();
            /*Connect to client*/
            Sender s = new Sender(ipAddress, Convert.ToInt32(port));
            SortedList<int,byte[]> tempListTasks = new SortedList<int,byte[]>(tasks);
            for (int i = 0; i < nbrPackets; i++)
            {
                if (tempListTasks.Count > 0)  //More tasks?
                {
                    int firstKey = tempListTasks.Keys[0];
                    byte[] data = tempListTasks[firstKey];
                    tempListTasks.Remove(firstKey); //remove temporary data, if the sender doesn't work
                    /*Add info of data*/
                    PacketInfo packetInfo = new PacketInfo(Command.Work, firstKey, "", data.Length, SecondSince1970.Get(),issueNumber);
                    if(!listPacketSended.ContainsKey(firstKey))
                        listPacketSended.Add(firstKey, packetInfo);
                    listWorksToSend.Add(packetInfo.ToByte());
                    /*Add data*/
                    listWorksToSend.Add(data);
                    listClient[ipAddress].currentWork.Add(firstKey); //Add to current client work
                }
                else
                    break;
            }

            /*Assembly the packets*/
            byte[] dataToSend = PacketAssembler.Assemble(listWorksToSend);
             /*Send data to client*/
            s.send(dataToSend);
            int nbrPaquetsToRemove = nbrPackets;
            if (nbrPackets > tasks.Count) //More packet to remove than number of task?
                nbrPaquetsToRemove = tasks.Count;
            for (int i = 0; i < nbrPaquetsToRemove; i++) //Remove real data
            {
                tasks.RemoveAt(0);
            }
        }
开发者ID:danielamor,项目名称:Distributed-computing,代码行数:47,代码来源:DataWork.cs

示例13: Main

        static void Main()
        {
            Dictionary<char, List<char>> graph = new Dictionary<char, List<char>>();
            FillTheGraph(graph);

            SortedList<char, int> predecessors = new SortedList<char, int>();
            FindPredecessors(graph, predecessors);

            bool nodeRemoved = true;

            foreach (var node in predecessors.Keys)
            {
                while (nodeRemoved)
                {
                    nodeRemoved = false;
                    //foreach (var node in predecessors.Keys)
                    //{
                    if (predecessors[node] <= 1)
                    {
                        foreach (var child in graph[node])
                        {
                            if (predecessors.ContainsKey(child))
                            {
                                predecessors[child]--;
                            }
                        }

                        predecessors.Remove(node);
                        nodeRemoved = true;
                        break;
                    }
                    //}
                }
            }

            Console.WriteLine("Acyclic: {0}", predecessors.Count == 0 ? "Yes" : "No");
        }
开发者ID:IvanMladenov,项目名称:Algorithms,代码行数:37,代码来源:Program.cs

示例14: TestGetIsReadOnlyBasic

        public void TestGetIsReadOnlyBasic()
        {
            String strValue;
            SortedList dic1;

            dic1 = new SortedList();
            for (int i = 0; i < 10; i++)
            {
                strValue = "String_" + i;
                dic1.Add(i, strValue);
            }

            for (int i = 0; i < 10; i++)
            {
                Assert.True(dic1.Contains(i));
            }

            //we'll do the ReadOnly test
            Assert.False(dic1.IsReadOnly);

            //we'll make sure by doing a modifiable things!!
            dic1.Remove(0);
            Assert.False(dic1.Contains(0));
        }
开发者ID:er0dr1guez,项目名称:corefx,代码行数:24,代码来源:PropertyIsReadOnlyTests.cs

示例15: Main

        /// <summary>
        /// 
        /// </summary>
        /// <param name="args">Only 1 paramater is accepted.</param>
        static void Main(string[] args)
        {
            Stopwatch timer;
            string word;
            SortedList<char, UInt64> characterCounts;
            UInt64 rank;
            UInt64 permutations;

            //Check argument length
            if (args.Length == 1)
            {
                //Start timer.
                timer = new Stopwatch();
                timer.Start();

                //Construct dictionary from input word.
                word = args[0];
                characterCounts = new SortedList<char, UInt64>();
                foreach (var character in word)
                {
                    if (characterCounts.ContainsKey(character))
                    {
                        characterCounts[character] += 1;
                    }
                    else
                    {
                        characterCounts.Add(character, 1);
                    }
                }

                //Compute rank by summing permutations before word.
                rank = 1;
                foreach (var character in word)
                {
                    for (int i = 0; characterCounts.Keys[i] != character && i < characterCounts.Count; i++)
                    {
                        permutations = Program.knockOutPermutations(characterCounts.Keys[i], characterCounts);
                        rank += permutations;
                    }
                    if (characterCounts[character] > 1)
                    {
                        characterCounts[character] -= 1;
                    }
                    else
                    {
                        characterCounts.Remove(character);
                    }
                }

                //Print out results.
                Console.Out.WriteLine("Rank of " + word + " is: " + rank);
                timer.Stop();
                Console.Out.WriteLine("Time elapsed: " + timer.ElapsedMilliseconds + " milliseconds.");
            }
            else
            {
                Console.Out.WriteLine("Usage: RankWord.exe <word>");
            }
        }
开发者ID:28ACB29,项目名称:Word-Ranker,代码行数:63,代码来源:Program.cs


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