Перенос страниц
This commit is contained in:
parent
4d57446057
commit
4c954c9186
129 changed files with 14 additions and 15 deletions
|
@ -0,0 +1,33 @@
|
|||
bool find1(int[] haystack, int needle)
|
||||
{
|
||||
foreach (v; haystack)
|
||||
{
|
||||
if (v == needle)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int[] find2(int[] haystack, int needle)
|
||||
{
|
||||
while (haystack.length > 0 && haystack[0] != needle)
|
||||
{
|
||||
haystack = haystack[1 .. $];
|
||||
}
|
||||
|
||||
return haystack;
|
||||
}
|
||||
|
||||
unittest
|
||||
{
|
||||
int[] a = [];
|
||||
assert(find2(a, 5) == []);
|
||||
a = [ 1, 2, 3 ];
|
||||
assert(find2(a, 0) == []);
|
||||
assert(find2(a, 1).length == 3);
|
||||
assert(find2(a, 2).length == 2);
|
||||
assert(a[0 .. $ - find2(a, 3).length] == [ 1, 2 ]);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue