CKTIS / C#
linear search: praktická referencia
linear search: praktická referencia: Lineárne hľadanie kontroluje prvky postupne až do zhody alebo konca.
Verzia: C# language and .NET 10 reference runtime
Syntax
// linear searchLineárne hľadanie kontroluje prvky postupne až do zhody alebo konca.
Použite na malé alebo jednorazové postupnosti bez indexu.
Opakované hľadanie O(n) môže ospravedlniť Dictionary alebo HashSet.
Absenciu výsledku reprezentujte bez konfliktu s platným indexom alebo hodnotou.
Úplný program skutočne používa linear search; presne očakávaný stdout je 1.
Príklady
using System;
using System.Buffers;
using System.Collections.Concurrent;
using System.Collections.Frozen;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.Json;
using System.Text.Json.Nodes;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Channels;
using System.Threading.Tasks;
using Number = System.Int32;
var values = new[] { 4, 7, 9 }; var index = Array.FindIndex(values, value => value == 7); Console.WriteLine(index);
Výsledok
1
Úplný program skutočne používa `linear search`; presne očakávaný stdout je `1`.