I am implementing recursive Median cut algorithm https://en.wikipedia.org/wiki/Median_cut and have problem, with my return it says "operator + can't be applied to operands of type List and List".
Here is my code so you get insight of what i'm asking about:
public static List<Color> Cut(List<Color> input,int n)
{
if (n == 1)
{
//creating List<Color> containing 1 color element which is
//average of all colors from input and returning this 1 element
//list ending our recursion
}
else
{
SortWithRespectToWidestChannel(input)
int median = input.Count / 2;
List<Color> l1 = new List<Color>();
List<Color> l2 = new List<Color>();
l1.AddRange(input.GetRange(0, median));
l2.AddRange(input.GetRange(median, input.Count - median));
return Cut(l1, n / 2) + Cut(l2, n / 2); // <---**here is problem**
}
So do you know how can I resolve my problem? Thank you in advance.
Try this if You want to have all Colors in one list.
Change:
return Cut(l1, n / 2) + Cut(l2, n / 2); // <---**here is problem**
to
var result = new List<Color>();
result.AddRange(Cut(l1, n / 2));
result.AddRange(Cut(l2, n / 2));
return result;
Give me feedback if i correct thing about Your problem.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.