简体   繁体   English

如何使用插值搜索C#搜索和返回多个元素

[英]How to search for and return multiple elements using a interpolation search c#

I currently have a working interpolation search which can detect a chosen number if it is stored within the array. 我目前有一个有效的内插搜索,如果将选定的数字存储在数组中,则可以检测到该数字。

My question is; 我的问题是; if the number being searched for is stored multiple times in the array how do I search for it multiple times and stop it from detecting the number multiple times? 如果要搜索的数字多次存储在数组中,如何多次搜索并阻止其多次检测到数字?

If you want to return multiple elements, you need to return an array of int (or list, or anything that can hold multiple values). 如果要返回多个元素,则需要返回一个int数组(或list或可以容纳多个值的任何东西)。

When you find a value, don't return immediately. 当您找到一个值时,不要立即返回。 Search for neighboring elements in the array to see if there is more than one occurrence. 搜索数组中的相邻元素,以查看是否存在多个事件。 You can track index of first occurrence, and last occurrence. 您可以跟踪第一次出现和最后一次出现的索引。 Once you checked both left and right side for multiple occurrences, store these values in the array and return the array. 一旦检查了左侧和右侧是否多次出现,请将这些值存储在数组中并返回数组。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM