{"id":360222,"date":"2024-05-21T00:48:54","date_gmt":"2024-05-21T00:48:54","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=360222"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=360222","title":{"rendered":"<span>\u00ab\u0412\u043d\u0435\u0448\u043d\u0438\u0435\u00bb \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438: \u0447\u0442\u043e \u044d\u0442\u043e, \u0437\u0430\u0447\u0435\u043c \u044d\u0442\u043e \u0438 \u043a\u0430\u043a \u044d\u0442\u043e \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c?<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439!<\/p>\n<p>\u0425\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u0438\u0437\u0432\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0437\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u0441\u044f\u043a\u0438 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0441\u044c \u0432\u043f\u0435\u0440\u0432\u044b\u0435. \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u043e \u0441\u0435\u0431\u0435: \u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0439 .NET backend \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0418 \u0432\u043e\u0442 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (2 \u043a\u0443\u0440\u0441 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430) \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438. \u0411\u044b\u043b\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u0435\u043e\u0440\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u0430 \u043b\u0435\u043d\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443. <\/p>\n<p>\u041d\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0441\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0443 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u043f\u043e\u0447\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e (\u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043f\u0430\u0440\u0430 \u0432\u0438\u0434\u0435\u043e \u043d\u0430 YouTube, \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0432\u0435\u0434\u0430\u0442\u044c \u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\u0445 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u043c \u043d\u0435 \u0441\u043b\u044b\u0448\u0430\u043b.<\/p>\n<p>\u041d\u0443-\u0441, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438<\/h2>\n<p>\u0427\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0437\u043d\u0430\u0447\u0438\u0442 &#171;\u0432\u043d\u0435\u0448\u043d\u044f\u044f&#187; \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430? \u041e\u0431\u044a\u044f\u0441\u043d\u044e: \u044d\u0442\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0430\u044f \u043d\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u0445\u0440\u0430\u043d\u044f\u0449\u0435\u0439\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 \u043d\u0430 \u0436\u0451\u0441\u0442\u043a\u043e\u043c \u0434\u0438\u0441\u043a\u0435. \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 (\u0434\u0430\u0436\u0435 \u041e\u0427\u0415\u041d\u042c \u0431\u043e\u043b\u044c\u0448\u0438\u0445) \u043e\u0431\u044a\u0451\u043c\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443. <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0451\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438: \u043f\u0440\u044f\u043c\u043e\u0439, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438 \u043c\u043d\u043e\u0433\u043e\u043d\u0438\u0442\u0435\u0432\u043e\u0439 (\u043c\u043d\u043e\u0433\u043e\u043f\u0443\u0442\u0435\u0432\u043e\u0439). \u0412\u0441\u0435 \u043e\u043d\u0438, \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u0432\u043e\u0435\u0439, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u043b\u0438\u044f\u043d\u0438\u0435\u043c (MergeSort). \u0422\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b.<\/p>\n<h2>1. \u041f\u0440\u044f\u043c\u043e\u0439 \u043c\u0435\u0442\u043e\u0434<\/h2>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0410, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u04301, \u04302, &#8230; , an, <br \/>\u0433\u0434\u0435 n &#8212; \u043a\u043e\u043b-\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u0414\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0434\u0432\u0430 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u0430 (\u0434\u0430\u043b\u0435\u0435 &#8212; \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b) B \u0438 C, \u043a\u043e\u043b-\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 n \/ 2.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0448\u0430\u0433\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430:<\/p>\n<ol>\n<li>\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u043f\u043e\u043e\u0447\u0435\u0440\u0451\u0434\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0432 \u043d\u0438\u0445 \u0441\u0442\u0440\u043e\u043a\u0438 (\u043d\u0435\u0447\u0451\u0442\u043d\u044b\u0435 \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0443 &#8212; \u0432 \u0444\u0430\u0439\u043b B, \u0447\u0451\u0442\u043d\u044b\u0435 &#8212; \u0432 \u0444\u0430\u0439\u043b C), \u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0438\u0445 \u0441\u043b\u0438\u044f\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 2 (\u043a\u0440\u043e\u043c\u0435, \u0431\u044b\u0442\u044c \u043c\u043e\u0436\u0435\u0442, \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0430\u0440\u044b \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c).<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u0431\u0438\u0442\u044c \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u043d\u0430 \u043f\u0430\u0440\u044b, \u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0441\u043b\u0438\u044f\u043d\u0438\u0435 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0431\u043e\u043b\u044c\u0448\u0435 1, \u0442\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0448\u0430\u0433\u0443 2.<\/p>\n<\/li>\n<\/ol>\n<p>\u0427\u0442\u043e \u0436\u0435, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438!<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u0448 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/p>\n<pre><code class=\"cs\">public class DirectOuterSort {   \/\/\u0421\u044e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b   private string? _headers;   \/\/\u043f\u043e\u043b\u0435 _iterations \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u0434\u043d\u043e\u0439 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0435    \/\/\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442.   \/\/\u043f\u043e\u043b\u0435 _segments \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432 \u043e\u0431\u043e\u0438\u0445   \/\/\u0444\u0430\u0439\u043b\u0430\u0445 \u0432 \u0441\u0443\u043c\u043c\u0435   private long _iterations, _segments;   \/\/\u0437\u0434\u0435\u0441\u044c \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430    \/\/(\u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0441\u0440\u0430\u0432\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432)   private readonly Type[] _typesOfTableColumns     = { typeof(int), typeof(string), typeof(DateTime) };   \/\/\u0418\u043d\u0434\u0435\u043a\u0441 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c   private readonly int _chosenField;    public DirectOuterSort(int chosenField)   {     _chosenField = chosenField;     _iterations = 1;   } }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u0430\u043b\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043e: \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441, \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b.<\/p>\n<pre><code class=\"cs\">private void SplitToFiles() {   _segments = 1;   using var fileA = new StreamReader(\"A.csv\");   _headers = fileA.ReadLine()!;    using var fileB = new StreamWriter(\"B.csv\");   using var fileC = new StreamWriter(\"C.csv\");   \/\/\u0412 \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u0441\u0447\u0438\u0442\u0430\u043d\u043d\u0430\u044f \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u044c   string? currentRecord = fileA.ReadLine();   bool flag = true;   int counter = 0;   \/\/\u0446\u0438\u043a\u043b \u043f\u0440\u0435\u043a\u0440\u0430\u0442\u0438\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u0439\u0434\u0451\u043c \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430   while (currentRecord is not null)   {     \/\/\u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u043e\u0432\u043e\u0439     if (counter == _iterations)     {       counter = 0;       flag = !flag;       _segments++;     }      if (flag)     {       \/\/\u0417\u0430\u043f\u0438\u0441\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b \u0412       fileB.WriteLine(currentRecord);     }     else     {       \/\/\u0417\u0430\u043f\u0438\u0441\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b \u0421       fileC.WriteLine(currentRecord);     }      \/\/\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c     currentRecord = fileA.ReadLine();     counter++;   } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443: \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0438\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u044b \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0438\u0437 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043d\u043e\u0432\u044b\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435.<\/p>\n<pre><code class=\"cs\">private void MergePairs() {   using var writerA = new StreamWriter(\"A.csv\");   using var readerB = new StreamReader(\"B.csv\");   using var readerC = new StreamReader(\"C.csv\");    \/\/\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 \u0441\u0432\u043e\u0451 \u043c\u0435\u0441\u0442\u043e, \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430   writerA.WriteLine(_headers);            string? elementB = readerB.ReadLine();   string? elementC = readerC.ReadLine();            int counterB = 0;   int counterC = 0;   \/\/\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c, \u043a\u043e\u0433\u0434\u0430    while (elementB is not null || elementC is not null)   {     string? currentRecord;     bool flag = false;      \/\/\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b B, \u0438\u043b\u0438 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u0440\u044b      \/\/\u0432 \u043d\u0451\u043c     if (elementB is null || counterB == _iterations)     {       currentRecord = elementC;     }     else if (elementC is null || counterC == _iterations) \/\/\u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u0431\u043b\u043e\u043a\u0443 if, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430 \u0421     {       currentRecord = elementB;       flag = true;     }     else     {       \/\/\u0415\u0441\u043b\u0438 \u043e\u0431\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430 \u0435\u0449\u0451 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c, \u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u043e \u043d\u0443\u0436\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e       if (CompareElements(elementB, elementC))       {         \/\/\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0412 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u0435\u043d\u044c\u0448\u0435         currentRecord = elementB;         flag = true;       }       else       {         \/\/\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0421 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u0435\u043d\u044c\u0448\u0435         currentRecord = elementC;       }     }      \/\/\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u0443\u044e \u043d\u0430\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044c     writerA.WriteLine(currentRecord);                  if (flag)     {       elementB = readerB.ReadLine();       counterB++;     }     else     {       elementC = readerC.ReadLine();       counterC++;     }      if (counterB != _iterations || counterC != _iterations)     {       continue;     }      \/\/\u0415\u0441\u043b\u0438 \u0441\u0435\u0440\u0438\u0438 \u0432 \u043e\u0431\u043e\u0438\u0445 \u0444\u0430\u0439\u043b\u0430\u0445 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c, \u0442\u043e \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0438     counterC = 0;     counterB = 0;   }    _iterations *= 2; }  \/\/\u041c\u0435\u0442\u043e\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0435\u0433\u043e \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \/\/\u0412\u0435\u0440\u043d\u0451\u0442 true, \u0435\u0441\u043b\u0438 element1 \u043c\u0435\u043d\u044c\u0448\u0435 element2 private bool CompareElements(string? element1, string? element2) {   if (_typesOfTableColumns[_chosenField].IsEquivalentTo(typeof(int)))   {     return int.Parse(element1!.Split(';')[_chosenField])       .CompareTo(int.Parse(element2!.Split(';')[_chosenField])) &lt; 0;   }       if (_typesOfTableColumns[_chosenField].IsEquivalentTo(typeof(DateTime)))   {     return DateTime.Parse(element1!.Split(';')[_chosenField])       .CompareTo(DateTime.Parse(element2!.Split(';')[_chosenField])) &lt; 0;   }    return string.Compare(element1!.Split(';')[_chosenField],                          element2!.Split(';')[_chosenField],                         StringComparison.Ordinal) &lt; 0; }<\/code><\/pre>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043d\u0430\u0448 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<pre><code class=\"cs\">public void Sort() {   while (true)   {     \/\/\u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b     SplitToFiles();     \/\/\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u043e\u0434\u043d\u0430, \u0437\u043d\u0430\u0447\u0438\u0442, \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b     if (_segments == 1)     {       break;     }      \/\/\u0421\u043b\u0438\u0432\u0430\u0435\u043c \u0432\u043c\u0435\u0441\u0442\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0438\u0437 \u043f\u043e\u0434 \u0444\u0430\u0439\u043b\u043e\u0432     MergePairs();   } }<\/code><\/pre>\n<p>\u0421 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438. \u0418\u0437 \u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u044b\u0434\u0435\u043b\u044e:<\/p>\n<ul>\n<li>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 &#8212; \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432 B \u0438 C (\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u043d\u043e \u0432\u0441\u044f\u043a\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438).<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043e log2(n) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0438 (log2(n) + 1) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043d\u0443\u0436\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0438\u0441\u0435\u0439).<\/p>\n<\/li>\n<li>\n<p>8 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 &#8212; 3 \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0438 4 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>16 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 &#8212; 4 \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0438 5 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<li>\n<p>1024 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 &#8212; 10 \u0441\u043b\u0438\u044f\u043d\u0438\u0439 \u0438 11 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<h2>2. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/h2>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e, \u0447\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c, \u0442.\u0435. \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <strong><em>\u0441\u0435\u0440\u0438\u0438<\/em><\/strong>.<\/p>\n<p><strong><em>\u0421\u0435\u0440\u0438\u044f &#8212; <\/em><\/strong>\u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0438\u0439 \u043f\u0440\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0441\u043b\u0438\u044f\u043d\u0438\u0438. \u0422. \u0435. \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u0441\u043b\u0438\u044f\u043d\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0441 \u043f\u0430\u0440\u0430\u043c\u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u044e\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443, \u0430 \u0441 \u043f\u0430\u0440\u0430\u043c\u0438 \u0441\u0435\u0440\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u043f\u043e \u0434\u043b\u0438\u043d\u0435.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e \u0436\u0435, \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0440\u0430\u0437. \u0421 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439!<\/p>\n<pre><code class=\"cs\">public class NaturalOuterSort {     private string? _headers;     private readonly int _chosenField;     private readonly Type[] _columnOfTableTypes          = { typeof(int), typeof(string), typeof(DateTime) };     \/\/\u0412 \u044d\u0442\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0434\u043b\u0438\u043d\u044b \u0432\u0441\u0435\u0445 \u0441\u0435\u0440\u0438\u0439 \u0432 \u043e\u0431\u043e\u0438\u0445 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430\u0445     private readonly List&lt;int> _series = new();          public NaturalOuterSort(int chosenField)     {         _chosenField = chosenField;     } }<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441\u0440\u0430\u0437\u0443 \u0431\u0440\u043e\u0441\u0430\u044e\u0442\u0441\u044f \u0432 \u0433\u043b\u0430\u0437\u0430:<\/p>\n<ol>\n<li>\n<p> \u041f\u0440\u043e\u043f\u0430\u043b\u0438 \u043f\u043e\u043b\u044f _iterations \u0438 _segments, \u0442.\u043a. \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u043d\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u044b \u0438 \u043a\u043e\u043b-\u0432\u043e \u0441\u0435\u0440\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0435 _series, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u044b \u043d\u0430\u0448\u0438\u0445 \u0441\u0435\u0440\u0438\u0439<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 &#8212; \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b.<\/p>\n<pre><code class=\"cs\">private void SplitToFiles() {   using var fileA = new StreamReader(\"A.csv\");   _headers = fileA.ReadLine();            using var fileB = new StreamWriter(\"B.csv\");   using var fileC = new StreamWriter(\"C.csv\");   \/\/\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b, \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0437\u0430 \u043d\u0435\u0439, \u0447\u0442\u043e\u0431\u044b    \/\/\u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0438\u0445 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u0441\u0435\u0440\u0438\u044f \u0438\u043b\u0438 \u043d\u0435\u0442   string? firstStr = fileA.ReadLine();   string? secondStr = fileA.ReadLine();   bool flag = true;   int counter = 0;   while (firstStr is not null)   {     \/\/\u0414\u043e\u043f. \u0444\u043b\u0430\u0433 \u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0438\u0438 \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u044d\u0442\u043e\u0439     \/\/\u0441\u0430\u043c\u043e\u0439 \u0441\u0435\u0440\u0438\u0438     bool tempFlag = flag;     if (secondStr is not null)     {       if (CompareElements(firstStr, secondStr))       {         counter++;       }       else       {         \/\/\u0415\u0441\u043b\u0438 \u0441\u0435\u0440\u0438\u044f \u043f\u0440\u0435\u0440\u0432\u0430\u043b\u0430\u0441\u044c, \u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0451 \u0434\u043b\u0438\u043d\u0443 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0438 \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u043c \u0441\u0447\u0451\u0442\u0447\u0438\u043a         tempFlag = !tempFlag;         _series.Add(counter + 1);         counter = 0;       }     }      if (flag)     {       fileB.WriteLine(firstStr);     }     else     {       fileC.WriteLine(firstStr);     }      \/\/\u0434\u0432\u0438\u0436\u0435\u043c\u0441\u044f \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0439 \u0437\u0430\u043f\u0438\u0441\u0438     firstStr = secondStr;     secondStr = fileA.ReadLine();     flag = tempFlag;   }            _series.Add(counter + 1); }<\/code><\/pre>\n<p>\u0417\u0430\u043f\u0438\u0441\u0438 \u0440\u0430\u0437\u0431\u0438\u0442\u044b \u043f\u043e \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430\u043c, \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u0441\u0442\u0430\u043b\u043e \u0432\u0440\u0435\u043c\u044f \u0441\u043b\u0438\u0442\u044c \u0438\u0445 \u0432\u043e\u0435\u0434\u0438\u043d\u043e. <\/p>\n<pre><code class=\"cs\">private void MergePairs() {   using var writerA = new StreamWriter(\"A.csv\");   using var readerB = new StreamReader(\"B.csv\");   using var readerC = new StreamReader(\"C.csv\");    \/\/\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u043f\u0440\u043e \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438   writerA.WriteLine(_headers);   \/\/\u0418\u043d\u0434\u0435\u043a\u0441, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u0441\u0435\u0440\u0438\u044f \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0435 B   int indexB = 0;   \/\/\u0418\u043d\u0434\u0435\u043a\u0441, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u0441\u0435\u0440\u0438\u044f \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0435 \u0421   int indexC = 1;   \/\/\u0421\u0447\u0451\u0442\u0447\u0438\u043a\u0438, \u0447\u0442\u043e\u0431\u044b \u0441\u043b\u0443\u0447\u0430\u0439\u043d\u043e \u043d\u0435 \u0432\u044b\u0439\u0442\u0438 \u0437\u0430 \u043f\u0440\u0435\u0434\u0435\u043b\u044b \u0441\u0435\u0440\u0438\u0438   int counterB = 0;   int counterC = 0;   string? elementB = readerB.ReadLine();   string? elementC = readerC.ReadLine();   \/\/\u0426\u0438\u043a\u043b \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u0442 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0442\u043e\u043b\u044c\u043a\u043e \u043a\u043e\u0433\u0434\u0430    while (elementB is not null || elementC is not null)   {     if (counterB == _series[indexB] &amp;&amp; counterC == _series[indexC])     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u0435\u0440\u0438\u0439 \u0432 \u043e\u0431\u043e\u0438\u0445 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430\u0445       counterB = 0;       counterC = 0;       indexB += 2;       indexC += 2;       continue;     }                   if (indexB == _series.Count || counterB == _series[indexB])     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u0435\u0440\u0438\u0438 \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0435 B       writerA.WriteLine(elementC);       elementC = readerC.ReadLine();       counterC++;       continue;     }      if (indexC == _series.Count || counterC == _series[indexC])     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0441\u0435\u0440\u0438\u0438 \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0435 C       writerA.WriteLine(elementB);       elementB = readerB.ReadLine();       counterB++;       continue;     }      \/\/\u0421\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u0438 \u0432\u043f\u0438\u0441\u044b\u0432\u0430\u043c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043c\u0435\u043d\u044c\u0448\u0443\u044e \u0438\u0437 \u043d\u0438\u0445     if (CompareElements(elementB, elementC))     {       writerA.WriteLine(elementB);       elementB = readerB.ReadLine();       counterB++;     }     else     {       writerA.WriteLine(elementC);       elementC = readerC.ReadLine();       counterC++;     }   } }  \/\/\u041c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u043e \u0437\u0430\u0434\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e \u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0435\u0433\u043e \u0442\u0438\u043f\u0430 \u0434\u0430\u043d\u043d\u044b\u0445 private bool CompareElements(string? element1, string? element2) {   if (_columnOfTableTypes[_chosenField].IsEquivalentTo(typeof(int)))   {     return int.Parse(element1!.Split(';')[_chosenField])         .CompareTo(int.Parse(element2!.Split(';')[_chosenField])) &lt;= 0;   }    if (_columnOfTableTypes[_chosenField].IsEquivalentTo(typeof(DateTime)))   {     return DateTime.Parse(element1!.Split(';')[_chosenField])         .CompareTo(DateTime.Parse(element2!.Split(';')[_chosenField])) &lt;= 0;   }    return string.Compare(element1!.Split(';')[_chosenField],                          element2!.Split(';')[_chosenField],                         StringComparison.Ordinal) &lt;= 0; }<\/code><\/pre>\n<p>\u041d\u0443 \u0438 \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u043e\u0435\u0434\u0438\u043d\u043e, \u0447\u0442\u043e\u0431\u044b \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u0443\u044e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443.<\/p>\n<pre><code class=\"cs\">public void Sort() {   while (true)   {     _series.Clear();     SplitToFiles();     \/\/\u0415\u0441\u043b\u0438 \u0443 \u043d\u0430\u0441 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u0432\u0441\u0435\u0433\u043e \u043e\u0434\u043d\u0430 \u0441\u0435\u0440\u0438\u044f, \u0437\u043d\u0430\u0447\u0438\u0442, \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b     if (_series.Count == 1)     {       break;     }      MergePairs();   } }<\/code><\/pre>\n<p>\u0418\u0437 \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u0438\u044f\u043d\u0438\u044f:<\/p>\n<ul>\n<li>\n<p>\u0427\u0438\u0441\u043b\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439\/\u0441\u043b\u0438\u044f\u043d\u0438\u0439 \u0444\u0430\u0439\u043b\u043e\u0432 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0442\u043e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435 \u0445\u0443\u0436\u0435, \u0447\u0435\u043c \u043f\u0440\u0438 \u043f\u0440\u0438\u043c\u0435\u043d\u0435\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0441\u043b\u0438\u044f\u043d\u0438\u044f, \u0430 \u0432 \u0441\u0440\u0435\u0434\u043d\u0435\u043c &#8212; \u0434\u0430\u0436\u0435 \u043b\u0443\u0447\u0448\u0435.<\/p>\n<\/li>\n<li>\n<p>\u0421 \u0434\u0440\u0443\u0433\u043e\u0439 \u0441\u0442\u043e\u0440\u043e\u043d\u044b, \u0443\u0432\u0435\u043b\u0438\u0447\u0438\u0432\u0430\u0435\u0442\u0441\u044f \u043a\u043e\u043b-\u0432\u043e \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u0439 \u0437\u0430 \u0441\u0447\u0451\u0442 \u0442\u0435\u0445, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0442\u0440\u0435\u0431\u0443\u044e\u0442\u0441\u044f \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u0438\u044f \u043a\u043e\u043d\u0446\u043e\u0432 \u0441\u0435\u0440\u0438\u0439. \u041a\u0440\u043e\u043c\u0435 \u0442\u043e\u0433\u043e, \u043f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u0434\u043b\u0438\u043d\u0430 \u0441\u0435\u0440\u0438\u0439 \u043d\u0435 \u0444\u0438\u043a\u0441\u0438\u0440\u043e\u0432\u0430\u043d\u0430, \u0442\u043e \u043c\u0430\u043a\u0441\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0440\u0430\u0437\u043c\u0435\u0440 \u0444\u0430\u0439\u043b\u043e\u0432 B \u0438 C \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0431\u043b\u0438\u0437\u043e\u043a \u043a \u0440\u0430\u0437\u043c\u0435\u0440\u0443 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 A.<\/p>\n<\/li>\n<\/ul>\n<h2>3. \u041c\u043d\u043e\u0433\u043e\u043d\u0438\u0442\u0435\u0432\u043e\u0439 (\u043c\u043d\u043e\u0433\u043e\u043f\u0443\u0442\u0435\u0432\u043e\u0439) \u043c\u0435\u0442\u043e\u0434<\/h2>\n<p>\u041f\u0440\u043e\u0446\u0435\u0441\u0441 \u043c\u043d\u043e\u0433\u043e\u043f\u0443\u0442\u0435\u0432\u043e\u0433\u043e \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u043f\u043e\u0447\u0442\u0438 \u043a\u0430\u043a \u0434\u0432\u0435 \u043a\u0430\u043f\u043b\u0438 \u0432\u043e\u0434\u044b \u0441\u0445\u043e\u0436 \u0441 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u043e\u043c \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0441\u043b\u0438\u044f\u043d\u0438\u044f. \u0417\u0430 \u043e\u0434\u043d\u0438\u043c \u043b\u0438\u0448\u044c \u0442\u0435\u043c \u0438\u0441\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435 \u0434\u0432\u0443\u0445 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u043e\u0432. \u0412 \u0441\u0432\u043e\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044f \u043f\u0440\u043e\u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0438\u0440\u0443\u044e \u0442\u0440\u0451\u0445\u043f\u0443\u0442\u0435\u0432\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 (\u0437\u043d\u0430\u0447\u0438\u0442, \u043a\u043e\u043b-\u0432\u043e \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u043e\u0432 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u043e \u0442\u0440\u0451\u043c).<\/p>\n<p>\u0423\u0436\u0435 \u043f\u043e \u0442\u0440\u0430\u0434\u0438\u0446\u0438\u0438, \u043d\u0430\u0447\u043d\u0451\u043c \u0441 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u0438 \u043f\u043e\u043b\u0435\u0439.<\/p>\n<pre><code class=\"cs\">public class MultiThreadOuterSort {     private string? _headers;     private readonly int _chosenField;     private long _iterations, _segments;     private readonly Type[] _columnOfTableTypes =         { typeof(int), typeof(string), typeof(DateTime) };      public MultiThreadOuterSort(int chosenField)     {         _chosenField = chosenField;         _iterations = 1;     } }<\/code><\/pre>\n<p>\u0417\u0434\u0435\u0441\u044c \u043c\u044b \u0432\u0438\u0434\u0438\u043c \u0443\u0436\u0435 \u0437\u043d\u0430\u043a\u043e\u043c\u044b\u0435 \u043d\u0430\u043c \u043f\u043e\u043b\u044f, \u0438 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0435 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0438\u0437 \u043d\u0438\u0445 \u043d\u0438\u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043d\u0435 \u0438\u0437\u043c\u0435\u043d\u0438\u043b\u043e\u0441\u044c. \u041f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443 &#8212; \u043a \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044e \u043d\u0430 \u0444\u0430\u0439\u043b\u044b.<\/p>\n<pre><code class=\"cs\">private void SplitToFiles() {   _segments = 1;   using var fileA = new StreamReader(\"A.csv\");   _headers = fileA.ReadLine();            using var fileB = new StreamWriter(\"B.csv\");   using var fileC = new StreamWriter(\"C.csv\");   using var fileD = new StreamWriter(\"D.csv\");   string? currentRecord = fileA.ReadLine();   \/\/\u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u0430\u044f flag \u043f\u043e\u043c\u0435\u043d\u044f\u043b\u0430 \u0441\u0432\u043e\u0439 \u0442\u0438\u043f \u0441 bool \u043d\u0430 int, \u0442.\u043a. \u0442\u0435\u043f\u0435\u0440\u044c \u043d\u0430\u043c \u043d\u0443\u0436\u043d\u043e \u0431\u043e\u043b\u044c\u0448\u0435   \/\/\u0434\u0432\u0443\u0445 \u0437\u043d\u0430\u0447\u0435\u043d\u0438\u0439   int flag = 0;   int counter = 0;   while (currentRecord is not null)   {     if (counter == _iterations)     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438       counter = 0;       flag = GetNextFileIndexToWrite(flag);       _segments++;     }      switch (flag)     {       case 0:           fileB.WriteLine(currentRecord);           break;       case 1:           fileC.WriteLine(currentRecord);           break;       case 2:           fileD.WriteLine(currentRecord);           break;     }          currentRecord = fileA.ReadLine();     counter++;   } }  \/\/\u041c\u0435\u0442\u043e\u0434 \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0438\u043d\u0434\u0435\u043a\u0441\u0430 \u0444\u0430\u0439\u043b\u0430 \u0434\u043b\u044f \u0437\u0430\u043f\u0438\u0441\u0438 (B = 0, C = 1, D = 2) private static int GetNextFileIndexToWrite(int currentIndex)         => currentIndex switch         {             0 => 1,             1 => 2,             2 => 0,             _ => throw new Exception(\"\u0427\u0442\u043e-\u0442\u043e \u0432\u044b\u0448\u043b\u043e \u0438\u0437 \u043f\u043e\u0434 \u043a\u043e\u043d\u0442\u0440\u043e\u043b\u044f. \u0411\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0440\u0430\u0442\u044c\u0441\u044f\")         };<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043c\u0435\u0442\u043e\u0434 \u0434\u043b\u044f \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u0442\u0440\u0451\u0445 \u0444\u0430\u0439\u043b\u043e\u0432. \u041e\u043d \u0443 \u043c\u0435\u043d\u044f \u043f\u043e\u043b\u0443\u0447\u0438\u043b\u0441\u044f \u0434\u043e\u0432\u043e\u043b\u044c\u043d\u043e \u0433\u0440\u043e\u043c\u043e\u0437\u0434\u043a\u0438\u043c (\u0438\u0437-\u0437\u0430 \u043f\u0440\u043e\u0432\u0435\u0440\u043e\u043a \u0438\u0441\u043a\u043b\u044e\u0447\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0441\u0438\u0442\u0443\u0430\u0446\u0438\u0439, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u043f\u0440\u0438 \u043a\u043e\u043d\u0446\u0435 \u0441\u0435\u0440\u0438\u0438 \u0432 \u043e\u0434\u043d\u043e\u043c \u0438\u043b\u0438 \u0434\u0432\u0443\u0445 \u0438\u0437 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u043e\u0432). \u041f\u043e\u044d\u0442\u043e\u043c\u0443 \u0431\u0443\u0434\u0443 \u0440\u0430\u0434 \u043f\u0440\u0435\u0434\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u043c \u043f\u043e \u0443\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u044e \u0447\u0438\u0442\u0430\u0435\u043c\u043e\u0441\u0442\u0438 \u043a\u043e\u0434\u0430 \u0438 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043e\u043a \u0432 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u044f\u0445.<\/p>\n<\/p>\n<pre><code class=\"cs\">private void MergeFiles() {   using var writerA = new StreamWriter(\"A.csv\");            using var readerB = new StreamReader(\"B.csv\");   using var readerC = new StreamReader(\"C.csv\");   using var readerD = new StreamReader(\"D.csv\");            writerA.WriteLine(_headers);    string? elementB = readerB.ReadLine();   string? elementC = readerC.ReadLine();   string? elementD = readerD.ReadLine();            int counterB = 0;   int counterC = 0;   int counterD = 0;   while (elementB is not null || elementC is not null || elementD is not null)   {     string? currentRecord;     int flag;      if (CheckElement(elementB, counterB) &amp;&amp; !CheckElement(elementC, counterC) &amp;&amp; !CheckElement(elementD, counterD))     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 B       (currentRecord, flag) = GetMinOfElements(               elementC,                elementD) switch         {           0 => (elementC, 1),           1 => (elementD, 2)         };     }     else if (CheckElement(elementC, counterC) &amp;&amp; !CheckElement(elementB, counterB) &amp;&amp; !CheckElement(elementD, counterD))     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 \u0421       (currentRecord, flag) = GetMinOfElements(               elementB,                elementD) switch       {         0 => (elementB, 0),         1 => (elementD, 2)       };     }     else if (CheckElement(elementD, counterD) &amp;&amp; !CheckElement(elementB, counterB) &amp;&amp; !CheckElement(elementC, counterC))     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u0442\u043e\u043b\u044c\u043a\u043e \u0432 \u0444\u0430\u0439\u043b\u0435 D       (currentRecord, flag) = GetMinOfElements(               elementB,                elementC) switch       {         0 => (elementB, 0),         1 => (elementC, 1)       };     }     else if (counterB == _iterations &amp;&amp; counterC == _iterations)     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 \u0412 \u0438 \u0421       currentRecord = elementD;       flag = 2;     }     else if (counterB == _iterations &amp;&amp; counterD == _iterations)     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 \u0412 \u0438 D       currentRecord = elementC;       flag = 1;     }     else if (counterC == _iterations &amp;&amp; counterD == _iterations)     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 C \u0438 D       currentRecord = elementB;       flag = 0;     }     else     {       \/\/\u0421\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u043d\u0438 \u043e\u0434\u043d\u0430 \u0438\u0437 3 \u0446\u0435\u043f\u043e\u0447\u0435\u043a       (currentRecord, flag) = GetMinOfElements(               elementB,                elementC,                elementD) switch       {         0 => (elementB, 0),         1 => (elementC, 1),         2 => (elementD, 2)       };     }                  switch (flag)     {       case 0:           writerA.WriteLine(currentRecord);           elementB = readerB.ReadLine();           counterB++;           break;       case 1:           writerA.WriteLine(currentRecord);           elementC = readerC.ReadLine();           counterC++;           break;       case 2:           writerA.WriteLine(currentRecord);           elementD = readerD.ReadLine();           counterD++;           break;     }      if (counterB != _iterations || counterC != _iterations || counterD != _iterations)     {       continue;     }      \/\/\u041e\u0431\u043d\u0443\u043b\u044f\u0435\u043c \u0432\u0441\u0435 3 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0430, \u0435\u0441\u043b\u0438 \u0434\u043e\u0441\u0442\u0438\u0433\u043b\u0438 \u043a\u043e\u043d\u0446\u0430 \u0432\u0441\u0435\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0432\u043e \u0432\u0441\u0435\u0445 \u0444\u0430\u0439\u043b\u0430\u0445     counterC = 0;     counterB = 0;     counterD = 0;   }    _iterations *= 3; }  \/\/\u041d\u0438\u0436\u0435 \u0434\u0430\u043d \u0440\u044f\u0434 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0434\u043b\u044f \u043f\u043e\u0438\u0441\u043a\u0430 \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u043e\u0433\u043e \u0438\u0437 3 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 (\u0441 \u0443\u0447\u0451\u0442\u043e\u043c \u0442\u043e\u0433\u043e), \/\/\u0447\u0442\u043e \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0438\u0437 \u043d\u0438\u0445 \u043c\u043e\u0433\u0443\u0442 \u043e\u0442\u0441\u0443\u0442\u0441\u0442\u0432\u043e\u0432\u0430\u0442\u044c private int GetMinOfElements(params string?[] elements) {     if (elements.Contains(null))     {         switch (elements.Length)         {             case 2:                 return elements[0] is null ? 1 : 0;             case 3 when elements[0] is null &amp;&amp; elements[1] is null:                 return 2;             case 3 when elements[0] is null &amp;&amp; elements[2] is null:                 return 1;             case 3 when elements[1] is null &amp;&amp; elements[2] is null:                 return 0;         }     }          if (_columnOfTableTypes[_chosenField].IsEquivalentTo(typeof(int)))     {         return GetMinInt(elements             .Select(s => s is null ? int.MaxValue : int.Parse(s.Split(';')[_chosenField]))             .ToArray());     }      if (_columnOfTableTypes[_chosenField].IsEquivalentTo(typeof(DateTime)))     {         return GetMinDateTime(elements             .Select(s => s is null ? DateTime.MaxValue: DateTime.Parse(s.Split(';')[_chosenField]))             .ToArray());     }      return GetMinString(elements!); }  private int GetMinString(IReadOnlyList&lt;string> elements) {     if (elements.Count == 1)     {         return 0;     }      var min = elements[0].Split(';')[_chosenField];     var minIndex = 0;     for (var i = 1; i &lt; elements.Count; i++)     {         if (string.Compare(elements[i].Split(';')[_chosenField], min, StringComparison.Ordinal) > 0)         {             continue;         }          min = elements[i].Split(';')[_chosenField];         minIndex = i;     }          return minIndex;     }      private static int GetMinInt(IReadOnlyList&lt;int> elements)     {         if (elements.Count == 1)         {             return 0;         }          var min = elements[0];         var minIndex = 0;         for (var i = 1; i &lt; elements.Count; i++)         {             if (elements[i] > min)             {                 continue;             }              min = elements[i];             minIndex = i;         }          return minIndex;     }      private static int GetMinDateTime(IReadOnlyList&lt;DateTime> elements)     {         if (elements.Count == 1)         {             return 0;         }          var min = elements[0];         var minIndex = 0;         for (var i = 1; i &lt; elements.Count; i++)         {             if (DateTime.Compare(elements[i], min) > 0)             {                 continue;             }              min = elements[i];             minIndex = i;         }          return minIndex;     }      private bool CheckElement(string? element, int counter)         => element is null || counter == _iterations;<\/code><\/pre>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u0444\u0438\u043d\u0430\u043b\u044c\u043d\u044b\u0439 \u0448\u0442\u0440\u0438\u0445. \u0421\u043e\u0435\u0434\u0438\u043d\u044f\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u044b \u0432\u043c\u0435\u0441\u0442\u0435 \u0443\u0436\u0435 \u043f\u0440\u0438\u0432\u044b\u0447\u043d\u044b\u043c \u043d\u0430\u043c \u0441\u043f\u043e\u0441\u043e\u0431\u043e\u043c.<\/p>\n<pre><code class=\"cs\">public void Sort() {   while (true)   {     SplitToFiles();          if (_segments == 1)     {       break;     }      MergeFiles();   } }<\/code><\/pre>\n<p>\u041f\u043e \u043c\u0435\u0440\u0435 \u0443\u0432\u0435\u043b\u0438\u0447\u0435\u043d\u0438\u044f \u0434\u043b\u0438\u043d\u044b \u0443\u0436\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0435 \u0444\u0430\u0439\u043b\u044b \u0441 \u0431\u043e\u043b\u044c\u0448\u0438\u043c\u0438 \u043d\u043e\u043c\u0435\u0440\u0430\u043c\u0438 (\u043d\u0430\u0447\u0438\u043d\u0430\u044f \u0441 \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u0435\u0433\u043e) \u043f\u0435\u0440\u0435\u0441\u0442\u0430\u044e\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f, \u0442.\u043a. \u0438\u043c &#171;\u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0451\u0442\u0441\u044f&#187; \u043d\u0438 \u043e\u0434\u043d\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0438.<\/p>\n<p>\u041a\u043e\u043b-\u0432\u043e \u043f\u0440\u043e\u0445\u043e\u0434\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0431\u0443\u0434\u0435\u0442 \u0440\u0430\u0432\u043d\u044b\u043c loga(n), \u0433\u0434\u0435 \u0430 &#8212; \u043a\u043e\u043b-\u0432\u043e \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u043e\u0432, n &#8212; \u043a\u043e\u043b-\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435.<\/p>\n<h2>\u0423\u043b\u0443\u0447\u0448\u0435\u043d\u0438\u0435 \u044d\u0444\u0444\u0435\u043a\u0442\u0438\u0432\u043d\u043e\u0441\u0442\u0438 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438<\/h2>\n<p>\u0414\u0443\u043c\u0430\u044e, \u044d\u0442\u043e \u043f\u0440\u043e\u0437\u0432\u0443\u0447\u0438\u0442 \u043b\u043e\u0433\u0438\u0447\u043d\u043e, \u0435\u0441\u043b\u0438 \u044f \u0441\u043a\u0430\u0436\u0443, \u0447\u0442\u043e \u0447\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435 \u0441\u0435\u0440\u0438\u0439 &#8212; \u0442\u043e \u0442\u0435\u043c \u0431\u043e\u043b\u044c\u0448\u0435 \u043f\u0440\u043e\u0445\u043e\u0434\u043e\u0432 \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0443, \u0434\u0430\u0431\u044b \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0435\u0433\u043e.<\/p>\n<p>\u0421\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e, \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u043e\u043f\u0442\u0438\u043c\u0438\u0437\u0430\u0446\u0438\u0438 \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u0443\u043c\u0435\u043d\u044c\u0448\u0438\u0442\u044c \u043a\u043e\u043b-\u0432\u043e \u0441\u0435\u0440\u0438\u0439 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435. \u041a\u0430\u043a \u044d\u0442\u043e\u0433\u043e \u0434\u043e\u0431\u0438\u0442\u044c\u0441\u044f? \u0420\u0430\u0437\u0431\u0438\u0442\u044c \u044d\u0442\u043e\u0442 \u0444\u0430\u0439\u043b \u043d\u0430 \u043c\u0430\u043b\u0435\u043d\u044c\u043a\u0438\u0435 \u0447\u0430\u0441\u0442\u0438 (\u0442\u0430\u043a, \u0447\u0442\u043e\u0431\u044b \u043a\u0430\u0436\u0434\u0430\u044f \u0438\u0437 \u043d\u0438\u0445 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u043f\u043e\u043c\u0435\u0449\u0430\u043b\u0430\u0441\u044c \u0432 \u041e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u041f\u0430\u043c\u044f\u0442\u0438) \u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043a\u0430\u0436\u0434\u0443\u044e \u0438\u0437 \u043d\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u043c \u0432\u043d\u0443\u0442\u0440\u0435\u043d\u043d\u0435\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<h2>\u0417\u0430\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u0435<\/h2>\n<p>\u041a\u0430\u043a \u0438 \u0432\u0441\u0451 \u0432 \u044d\u0442\u043e\u043c \u043c\u0438\u0440\u0435, \u043c\u043e\u0439 \u0441\u043a\u0440\u043e\u043c\u043d\u044b\u0439 \u0440\u0430\u0441\u0441\u043a\u0430\u0437 \u043f\u043e\u0434\u0445\u043e\u0434\u0438\u0442 \u043a \u043a\u043e\u043d\u0446\u0443. \u041f\u043e\u0441\u0442\u0430\u0440\u0430\u043b\u0441\u044f \u0441\u0434\u0435\u043b\u0430\u0442\u044c \u044d\u0442\u0443 \u0441\u0442\u0430\u0442\u044c\u044e \u0432 \u0442\u043e\u043c \u0444\u043e\u0440\u043c\u0430\u0442\u0435, \u0432 \u043a\u0430\u043a\u043e\u043c \u0441\u0430\u043c \u0431\u044b \u0445\u043e\u0442\u0435\u043b \u0435\u0451 \u043d\u0430\u0439\u0442\u0438: \u043a\u0440\u0430\u0442\u043a\u0438\u0435, \u043d\u043e \u043f\u043e\u043d\u044f\u0442\u043d\u044b\u0435 \u043e\u0431\u044a\u044f\u0441\u043d\u0435\u043d\u0438\u044f, \u0438 \u0440\u0430\u0437\u0432\u0451\u0440\u043d\u0443\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043d\u044b\u0435 \u043f\u0440\u0438\u043c\u0435\u0440\u044b \u043a\u043e\u0434\u0430 \u0432 \u043b\u0438\u0441\u0442\u0438\u043d\u0433\u0430\u0445.<\/p>\n<p>\u0421\u043f\u0430\u0441\u0438\u0431\u043e \u0432\u0441\u0435\u043c, \u0447\u0442\u043e \u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u044d\u0442\u043e\u0433\u043e \u043c\u0435\u0441\u0442\u0430. \u0414\u043e \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0438\u0445 \u0441\u0442\u0430\u0442\u0435\u0439!<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/774088\/\"> https:\/\/habr.com\/ru\/articles\/774088\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u041f\u0440\u0438\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e \u0432\u0441\u0435\u0445 \u0447\u0438\u0442\u0430\u0442\u0435\u043b\u0435\u0439!<\/p>\n<p>\u0425\u043e\u0447\u0443 \u0441\u0440\u0430\u0437\u0443 \u0438\u0437\u0432\u0438\u043d\u0438\u0442\u044c\u0441\u044f \u0437\u0430 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u044b\u0435 \u043a\u043e\u0441\u044f\u043a\u0438 \u0432 \u0441\u0442\u0430\u0442\u044c\u0435, \u043d\u0430 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0435 \u043f\u0443\u0431\u043b\u0438\u043a\u0443\u044e\u0441\u044c \u0432\u043f\u0435\u0440\u0432\u044b\u0435. \u0415\u0441\u043b\u0438 \u0432\u043a\u0440\u0430\u0442\u0446\u0435 \u043e \u0441\u0435\u0431\u0435: \u044f \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0449\u0438\u0439 .NET backend \u0440\u0430\u0437\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a. \u0418 \u0432\u043e\u0442 \u0432 \u043f\u0440\u043e\u0446\u0435\u0441\u0441\u0435 \u0441\u0432\u043e\u0435\u0433\u043e \u043e\u0431\u0443\u0447\u0435\u043d\u0438\u044f (2 \u043a\u0443\u0440\u0441 \u0443\u043d\u0438\u0432\u0435\u0440\u0441\u0438\u0442\u0435\u0442\u0430) \u044f \u0441\u0442\u043e\u043b\u043a\u043d\u0443\u043b\u0441\u044f \u0441\u043e \u0432\u043d\u0435\u0448\u043d\u0438\u043c\u0438 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\u043c\u0438. \u0411\u044b\u043b\u043e \u043f\u043e\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u0435\u043e\u0440\u0438\u0438, \u0430 \u0442\u0430\u043a\u0436\u0435 \u0431\u044b\u043b\u0430 \u043b\u0435\u043d\u044c \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u044b\u0432\u0430\u0442\u044c \u0441\u0430\u043c\u043e\u043c\u0443. <\/p>\n<p>\u041d\u043e \u043f\u043e\u0441\u043b\u0435 \u043e\u043a\u043e\u043b\u043e \u043f\u043e\u043b\u0443\u0447\u0430\u0441\u0430 \u043f\u043e\u0438\u0441\u043a\u0430 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0438 \u043f\u043e \u0438\u043d\u0442\u0435\u0440\u043d\u0435\u0442\u0443 \u043d\u0435 \u043d\u0430\u0448\u0451\u043b \u043f\u043e\u0447\u0442\u0438 \u043d\u0438\u0447\u0435\u0433\u043e (\u0431\u0443\u043a\u0432\u0430\u043b\u044c\u043d\u043e \u043f\u0430\u0440\u0430 \u0432\u0438\u0434\u0435\u043e \u043d\u0430 YouTube, \u043d\u0435 \u0431\u043e\u043b\u044c\u0448\u0435). \u041f\u043e\u044d\u0442\u043e\u043c\u0443, \u0445\u043e\u0447\u0443 \u043f\u043e\u0434\u0435\u043b\u0438\u0442\u044c\u0441\u044f \u0441\u0432\u043e\u0438\u043c\u0438 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044f\u043c\u0438 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u0432, \u0430 \u0442\u0430\u043a\u0436\u0435 \u043f\u043e\u0432\u0435\u0434\u0430\u0442\u044c \u043e \u0432\u043d\u0435\u0448\u043d\u0438\u0445 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430\u0445 \u0434\u043b\u044f \u0442\u0435\u0445, \u043a\u0442\u043e \u043e \u043f\u043e\u0434\u043e\u0431\u043d\u043e\u043c \u043d\u0435 \u0441\u043b\u044b\u0448\u0430\u043b.<\/p>\n<p>\u041d\u0443-\u0441, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c!<\/p>\n<h2>\u041d\u0435\u043c\u043d\u043e\u0433\u043e \u0442\u0435\u043e\u0440\u0438\u0438<\/h2>\n<p>\u0427\u0442\u043e \u0432\u043e\u043e\u0431\u0449\u0435 \u0437\u043d\u0430\u0447\u0438\u0442 &#171;\u0432\u043d\u0435\u0448\u043d\u044f\u044f&#187; \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430? \u041e\u0431\u044a\u044f\u0441\u043d\u044e: \u044d\u0442\u043e \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430, \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0449\u0430\u044f \u043d\u0435 \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438, \u0430 \u0441 \u0438\u043d\u0444\u043e\u0440\u043c\u0430\u0446\u0438\u0435\u0439, \u0445\u0440\u0430\u043d\u044f\u0449\u0435\u0439\u0441\u044f \u0432 \u0444\u0430\u0439\u043b\u0430\u0445 \u043d\u0430 \u0436\u0451\u0441\u0442\u043a\u043e\u043c \u0434\u0438\u0441\u043a\u0435. \u041f\u0440\u0438\u043c\u0435\u043d\u044f\u0435\u0442\u0441\u044f, \u043a\u0430\u043a \u043f\u0440\u0430\u0432\u0438\u043b\u043e, \u0434\u043b\u044f \u0431\u043e\u043b\u044c\u0448\u0438\u0445 (\u0434\u0430\u0436\u0435 \u041e\u0427\u0415\u041d\u042c \u0431\u043e\u043b\u044c\u0448\u0438\u0445) \u043e\u0431\u044a\u0451\u043c\u043e\u0432 \u0434\u0430\u043d\u043d\u044b\u0445. \u041d\u0430\u043f\u0440\u0438\u043c\u0435\u0440, \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0430 \u0442\u0430\u0431\u043b\u0438\u0446 \u043f\u043e \u043e\u043f\u0440\u0435\u0434\u0435\u043b\u0451\u043d\u043d\u043e\u043c\u0443 \u0441\u0442\u043e\u043b\u0431\u0446\u0443. <\/p>\n<p>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u044b \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u0442\u0440\u0451\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u043d\u0435\u0448\u043d\u0435\u0439 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438: \u043f\u0440\u044f\u043c\u043e\u0439, \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u0438 \u043c\u043d\u043e\u0433\u043e\u043d\u0438\u0442\u0435\u0432\u043e\u0439 (\u043c\u043d\u043e\u0433\u043e\u043f\u0443\u0442\u0435\u0432\u043e\u0439). \u0412\u0441\u0435 \u043e\u043d\u0438, \u043f\u043e \u0441\u0443\u0442\u0438 \u0441\u0432\u043e\u0435\u0439, \u043f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u044f\u044e\u0442 \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0443 \u0441\u043b\u0438\u044f\u043d\u0438\u0435\u043c (MergeSort). \u0422\u043e\u043b\u044c\u043a\u043e \u0432\u043c\u0435\u0441\u0442\u043e \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043e\u0434\u043c\u0430\u0441\u0441\u0438\u0432\u044b \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0437\u0431\u0438\u0432\u0430\u0442\u044c \u0434\u0430\u043d\u043d\u044b\u0435 \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b.<\/p>\n<h2>1. \u041f\u0440\u044f\u043c\u043e\u0439 \u043c\u0435\u0442\u043e\u0434<\/h2>\n<p>\u041f\u0440\u0435\u0434\u043f\u043e\u043b\u043e\u0436\u0438\u043c, \u0447\u0442\u043e \u0438\u043c\u0435\u0435\u0442\u0441\u044f \u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0410, \u0441\u043e\u0441\u0442\u043e\u044f\u0449\u0438\u0439 \u0438\u0437 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u04301, \u04302, &#8230; , an, <br \/>\u0433\u0434\u0435 n &#8212; \u043a\u043e\u043b-\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439. \u0414\u043b\u044f \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0430\u043c \u043f\u043e\u043d\u0430\u0434\u043e\u0431\u044f\u0442\u0441\u044f \u0434\u0432\u0430 \u0432\u0441\u043f\u043e\u043c\u043e\u0433\u0430\u0442\u0435\u043b\u044c\u043d\u044b\u0445 \u0444\u0430\u0439\u043b\u0430 (\u0434\u0430\u043b\u0435\u0435 &#8212; \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b) B \u0438 C, \u043a\u043e\u043b-\u0432\u043e \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0432 \u043a\u0430\u0436\u0434\u043e\u043c \u0438\u0437 \u043d\u0438\u0445 \u0431\u0443\u0434\u0435\u0442 n \/ 2.<\/p>\n<p>\u041f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0448\u0430\u0433\u043e\u0432 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430:<\/p>\n<ol>\n<li>\n<p>\u0420\u0430\u0437\u0434\u0435\u043b\u0438\u0442\u044c \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b \u043c\u0435\u0436\u0434\u0443 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430\u043c\u0438, \u043f\u043e\u043e\u0447\u0435\u0440\u0451\u0434\u043d\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u044f \u0432 \u043d\u0438\u0445 \u0441\u0442\u0440\u043e\u043a\u0438 (\u043d\u0435\u0447\u0451\u0442\u043d\u044b\u0435 \u043f\u043e \u043d\u043e\u043c\u0435\u0440\u0443 &#8212; \u0432 \u0444\u0430\u0439\u043b B, \u0447\u0451\u0442\u043d\u044b\u0435 &#8212; \u0432 \u0444\u0430\u0439\u043b C), \u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0438\u0445 \u0441\u043b\u0438\u044f\u043d\u0438\u0435 \u043e\u0431\u0440\u0430\u0442\u043d\u043e \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b, \u043f\u043e\u043b\u0443\u0447\u0438\u0432 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0434\u043b\u0438\u043d\u043e\u0439 2 (\u043a\u0440\u043e\u043c\u0435, \u0431\u044b\u0442\u044c \u043c\u043e\u0436\u0435\u0442, \u043e\u0434\u043d\u043e\u0433\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430, \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u043f\u0430\u0440\u044b \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u043b\u043e\u0441\u044c).<\/p>\n<\/li>\n<li>\n<p>\u0420\u0430\u0437\u0431\u0438\u0442\u044c \u0438\u043c\u0435\u044e\u0449\u0438\u0435\u0441\u044f \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u043d\u0430 \u043f\u0430\u0440\u044b, \u0438 \u043e\u0441\u0443\u0449\u0435\u0441\u0442\u0432\u0438\u0442\u044c \u0441\u043b\u0438\u044f\u043d\u0438\u0435 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u043a\u0430\u0436\u0434\u043e\u0439 \u043f\u0430\u0440\u044b.<\/p>\n<\/li>\n<li>\n<p>\u0415\u0441\u043b\u0438 \u0447\u0438\u0441\u043b\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0431\u043e\u043b\u044c\u0448\u0435 1, \u0442\u043e \u043f\u0435\u0440\u0435\u0439\u0442\u0438 \u043a \u0448\u0430\u0433\u0443 2.<\/p>\n<\/li>\n<\/ol>\n<p>\u0427\u0442\u043e \u0436\u0435, \u043f\u0440\u0438\u0441\u0442\u0443\u043f\u0438\u043c \u043a \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438!<\/p>\n<p>\u0414\u043b\u044f \u043d\u0430\u0447\u0430\u043b\u0430 \u043e\u0431\u044a\u044f\u0432\u0438\u043c \u043a\u043b\u0430\u0441\u0441, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0430\u0445\u043e\u0434\u0438\u0442\u044c\u0441\u044f \u043d\u0430\u0448 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c<\/p>\n<pre><code class=\"cs\">public class DirectOuterSort {   \/\/\u0421\u044e\u0434\u0430 \u0431\u0443\u0434\u0435\u0442 \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0442\u044c\u0441\u044f \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0430\u043c\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b   private string? _headers;   \/\/\u043f\u043e\u043b\u0435 _iterations \u0443\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 \u0432 \u043e\u0434\u043d\u043e\u0439 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0439 \u0446\u0435\u043f\u043e\u0447\u043a\u0435    \/\/\u043d\u0430 \u0434\u0430\u043d\u043d\u044b\u0439 \u043c\u043e\u043c\u0435\u043d\u0442.   \/\/\u043f\u043e\u043b\u0435 _segments \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0435\u0442, \u0441\u043a\u043e\u043b\u044c\u043a\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432 \u043e\u0431\u043e\u0438\u0445   \/\/\u0444\u0430\u0439\u043b\u0430\u0445 \u0432 \u0441\u0443\u043c\u043c\u0435   private long _iterations, _segments;   \/\/\u0437\u0434\u0435\u0441\u044c \u0432 \u043d\u0443\u0436\u043d\u043e\u043c \u043f\u043e\u0440\u044f\u0434\u043a\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0442\u0438\u043f\u044b \u0434\u0430\u043d\u043d\u044b\u0445 \u043a\u0430\u0436\u0434\u043e\u0433\u043e \u0441\u0442\u043e\u043b\u0431\u0446\u0430    \/\/(\u043f\u043e\u043d\u0430\u0434\u043e\u0431\u0438\u0442\u0441\u044f \u0434\u043b\u044f \u043a\u043e\u0440\u0440\u0435\u043a\u0442\u043d\u043e\u0433\u043e \u0441\u0440\u0430\u0432\u0435\u043d\u0438\u044f \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432)   private readonly Type[] _typesOfTableColumns     = { typeof(int), typeof(string), typeof(DateTime) };   \/\/\u0418\u043d\u0434\u0435\u043a\u0441 \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u0433\u043e \u043f\u043e\u043b\u044f, \u043f\u043e \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u0443 \u0431\u0443\u0434\u0435\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u0442\u044c   private readonly int _chosenField;    public DirectOuterSort(int chosenField)   {     _chosenField = chosenField;     _iterations = 1;   } }<\/code><\/pre>\n<p>\u041d\u0430\u0447\u0430\u043b\u043e \u043f\u043e\u043b\u043e\u0436\u0435\u043d\u043e: \u0441\u043e\u0437\u0434\u0430\u043b\u0438 \u043a\u043b\u0430\u0441\u0441, \u043e\u0431\u044a\u044f\u0432\u0438\u043b\u0438 \u043d\u0443\u0436\u043d\u044b\u0435 \u043f\u043e\u043b\u044f. \u0422\u0435\u043f\u0435\u0440\u044c \u0434\u043e\u0431\u0430\u0432\u0438\u043c \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b.<\/p>\n<pre><code class=\"cs\">private void SplitToFiles() {   _segments = 1;   using var fileA = new StreamReader(\"A.csv\");   _headers = fileA.ReadLine()!;    using var fileB = new StreamWriter(\"B.csv\");   using var fileC = new StreamWriter(\"C.csv\");   \/\/\u0412 \u044d\u0442\u043e\u0439 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u043e\u0439 \u0431\u0443\u0434\u0435\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u0430\u044f \u0441\u0447\u0438\u0442\u0430\u043d\u043d\u0430\u044f \u0438\u0437 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430 \u0437\u0430\u043f\u0438\u0441\u044c   string? currentRecord = fileA.ReadLine();   bool flag = true;   int counter = 0;   \/\/\u0446\u0438\u043a\u043b \u043f\u0440\u0435\u043a\u0440\u0430\u0442\u0438\u0442\u0441\u044f, \u043a\u043e\u0433\u0434\u0430 \u043c\u044b \u0434\u043e\u0439\u0434\u0451\u043c \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430   while (currentRecord is not null)   {     \/\/\u0434\u043e\u0448\u043b\u0438 \u0434\u043e \u043a\u043e\u043d\u0446\u0430 \u0446\u0435\u043f\u043e\u0447\u043a\u0438, \u043f\u0435\u0440\u0435\u043a\u043b\u044e\u0447\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0437\u0430\u043f\u0438\u0441\u044c \u043d\u043e\u0432\u043e\u0439     if (counter == _iterations)     {       counter = 0;       flag = !flag;       _segments++;     }      if (flag)     {       \/\/\u0417\u0430\u043f\u0438\u0441\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b \u0412       fileB.WriteLine(currentRecord);     }     else     {       \/\/\u0417\u0430\u043f\u0438\u0441\u044c \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b \u0421       fileC.WriteLine(currentRecord);     }      \/\/\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0437\u0430\u043f\u0438\u0441\u044c     currentRecord = fileA.ReadLine();     counter++;   } }<\/code><\/pre>\n<p>\u0422\u0435\u043f\u0435\u0440\u044c \u043f\u0435\u0440\u0435\u0445\u043e\u0434\u0438\u043c \u043a \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c\u0443 \u0448\u0430\u0433\u0443: \u043d\u0430\u043f\u0438\u0448\u0435\u043c \u043c\u0435\u0442\u043e\u0434, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0431\u0443\u0434\u0435\u0442 \u0441\u043b\u0438\u0432\u0430\u0442\u044c \u043f\u0430\u0440\u044b \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a \u0438\u0437 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u043e\u0432 \u0432 \u043d\u043e\u0432\u044b\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u043c \u0444\u0430\u0439\u043b\u0435.<\/p>\n<pre><code class=\"cs\">private void MergePairs() {   using var writerA = new StreamWriter(\"A.csv\");   using var readerB = new StreamReader(\"B.csv\");   using var readerC = new StreamReader(\"C.csv\");    \/\/\u041d\u0435 \u0437\u0430\u0431\u044b\u0432\u0430\u0435\u043c \u0432\u0435\u0440\u043d\u0443\u0442\u044c \u0437\u0430\u0433\u043e\u043b\u043e\u0432\u043a\u0438 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u043d\u0430 \u0441\u0432\u043e\u0451 \u043c\u0435\u0441\u0442\u043e, \u0432 \u043d\u0430\u0447\u0430\u043b\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u043e\u0433\u043e \u0444\u0430\u0439\u043b\u0430   writerA.WriteLine(_headers);            string? elementB = readerB.ReadLine();   string? elementC = readerC.ReadLine();            int counterB = 0;   int counterC = 0;   \/\/\u0418\u0442\u0435\u0440\u0430\u0446\u0438\u0438 \u0431\u0443\u0434\u0443\u0442 \u043f\u0440\u043e\u0438\u0441\u0445\u043e\u0434\u0438\u0442\u044c, \u043a\u043e\u0433\u0434\u0430    while (elementB is not null || elementC is not null)   {     string? currentRecord;     bool flag = false;      \/\/\u041e\u0431\u0440\u0430\u0431\u0430\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0439, \u043a\u043e\u0433\u0434\u0430 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0441\u044f \u0432\u0435\u0441\u044c \u0444\u0430\u0439\u043b B, \u0438\u043b\u0438 \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u0438\u0437 \u0434\u0430\u043d\u043d\u043e\u0439 \u043f\u0430\u0440\u044b      \/\/\u0432 \u043d\u0451\u043c     if (elementB is null || counterB == _iterations)     {       currentRecord = elementC;     }     else if (elementC is null || counterC == _iterations) \/\/\u0430\u043d\u0430\u043b\u043e\u0433\u0438\u0447\u043d\u043e \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u043c\u0443 \u0431\u043b\u043e\u043a\u0443 if, \u043d\u043e \u0434\u043b\u044f \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430 \u0421     {       currentRecord = elementB;       flag = true;     }     else     {       \/\/\u0415\u0441\u043b\u0438 \u043e\u0431\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430 \u0435\u0449\u0451 \u043d\u0435 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c, \u0442\u043e \u0441\u0440\u0430\u0432\u043d\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u043f\u043e \u043d\u0443\u0436\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e       if (CompareElements(elementB, elementC))       {         \/\/\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0412 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u0435\u043d\u044c\u0448\u0435         currentRecord = elementB;         flag = true;       }       else       {         \/\/\u0415\u0441\u043b\u0438 \u0437\u0430\u043f\u0438\u0441\u044c \u0438\u0437 \u0444\u0430\u0439\u043b\u0430 \u0421 \u043e\u043a\u0430\u0437\u0430\u043b\u0430\u0441\u044c \u043c\u0435\u043d\u044c\u0448\u0435         currentRecord = elementC;       }     }      \/\/\u0417\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0432 \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u0443\u044e \u043d\u0430\u043c\u0438 \u0437\u0430\u043f\u0438\u0441\u044c     writerA.WriteLine(currentRecord);                  if (flag)     {       elementB = readerB.ReadLine();       counterB++;     }     else     {       elementC = readerC.ReadLine();       counterC++;     }      if (counterB != _iterations || counterC != _iterations)     {       continue;     }      \/\/\u0415\u0441\u043b\u0438 \u0441\u0435\u0440\u0438\u0438 \u0432 \u043e\u0431\u043e\u0438\u0445 \u0444\u0430\u0439\u043b\u0430\u0445 \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438\u0441\u044c, \u0442\u043e \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u043c \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0435 \u0441\u0447\u0451\u0442\u0447\u0438\u043a\u0438     counterC = 0;     counterB = 0;   }    _iterations *= 2; }  \/\/\u041c\u0435\u0442\u043e\u0434 \u0441\u0440\u0430\u0432\u043d\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043f\u043e \u0432\u044b\u0431\u0440\u0430\u043d\u043d\u043e\u043c\u0443 \u043f\u043e\u043b\u044e, \u0443\u0447\u0438\u0442\u044b\u0432\u0430\u044f \u0435\u0433\u043e \u0442\u0438\u043f \u0434\u0430\u043d\u043d\u044b\u0445 \/\/\u0412\u0435\u0440\u043d\u0451\u0442 true, \u0435\u0441\u043b\u0438 element1 \u043c\u0435\u043d\u044c\u0448\u0435 element2 private bool CompareElements(string? element1, string? element2) {   if (_typesOfTableColumns[_chosenField].IsEquivalentTo(typeof(int)))   {     return int.Parse(element1!.Split(';')[_chosenField])       .CompareTo(int.Parse(element2!.Split(';')[_chosenField])) &lt; 0;   }       if (_typesOfTableColumns[_chosenField].IsEquivalentTo(typeof(DateTime)))   {     return DateTime.Parse(element1!.Split(';')[_chosenField])       .CompareTo(DateTime.Parse(element2!.Split(';')[_chosenField])) &lt; 0;   }    return string.Compare(element1!.Split(';')[_chosenField],                          element2!.Split(';')[_chosenField],                         StringComparison.Ordinal) &lt; 0; }<\/code><\/pre>\n<p>\u0418, \u043d\u0430\u043a\u043e\u043d\u0435\u0446, \u043e\u0431\u044a\u0435\u0434\u0438\u043d\u0438\u043c \u044d\u0442\u0438 \u043c\u0435\u0442\u043e\u0434\u044b, \u0447\u0442\u043e\u0431\u044b \u0437\u0430\u0432\u0435\u0440\u0448\u0438\u0442\u044c \u043d\u0430\u0448 \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c \u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u043a\u0438.<\/p>\n<pre><code class=\"cs\">public void Sort() {   while (true)   {     \/\/\u0420\u0430\u0437\u0431\u0438\u0432\u0430\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u0438 \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b     SplitToFiles();     \/\/\u0415\u0441\u043b\u0438 \u043f\u043e\u0441\u043b\u0435 \u0440\u0430\u0437\u0434\u0435\u043b\u0435\u043d\u0438\u044f \u0446\u0435\u043f\u043e\u0447\u043a\u0430 \u043e\u0441\u0442\u0430\u043b\u0430\u0441\u044c \u043e\u0434\u043d\u0430, \u0437\u043d\u0430\u0447\u0438\u0442, \u0437\u0430\u043f\u0438\u0441\u0438 \u0432 \u0444\u0430\u0439\u043b\u0435 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u044b     if (_segments == 1)     {       break;     }      \/\/\u0421\u043b\u0438\u0432\u0430\u0435\u043c \u0432\u043c\u0435\u0441\u0442\u0435 \u0446\u0435\u043f\u043e\u0447\u043a\u0438 \u0438\u0437 \u043f\u043e\u0434 \u0444\u0430\u0439\u043b\u043e\u0432     MergePairs();   } }<\/code><\/pre>\n<p>\u0421 \u043f\u0435\u0440\u0432\u044b\u043c \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u043e\u043c \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0438. \u0418\u0437 \u0435\u0433\u043e \u043e\u0441\u043e\u0431\u0435\u043d\u043d\u043e\u0441\u0442\u0435\u0439 \u0432\u044b\u0434\u0435\u043b\u044e:<\/p>\n<ul>\n<li>\n<p>\u0412 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438 \u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u0434\u0432\u0435 \u043f\u0435\u0440\u0435\u043c\u0435\u043d\u043d\u044b\u0435 &#8212; \u0434\u043b\u044f \u043e\u0447\u0435\u0440\u0435\u0434\u043d\u044b\u0445 \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u0438\u0437 \u0444\u0430\u0439\u043b\u043e\u0432 B \u0438 C (\u043d\u0430 \u0441\u0430\u043c\u043e\u043c \u0434\u0435\u043b\u0435 \u0447\u0443\u0442\u044c \u0431\u043e\u043b\u044c\u0448\u0435, \u043d\u043e \u0432\u0441\u044f\u043a\u043e \u043b\u0443\u0447\u0448\u0435, \u0447\u0435\u043c \u0445\u0440\u0430\u043d\u0438\u0442\u044c \u043e\u0433\u0440\u043e\u043c\u043d\u044b\u0435 \u0442\u0430\u0431\u043b\u0438\u0446\u044b \u0441 \u0434\u0430\u043d\u043d\u044b\u043c\u0438 \u0446\u0435\u043b\u0438\u043a\u043e\u043c \u0432 \u043e\u043f\u0435\u0440\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u0430\u043c\u044f\u0442\u0438).<\/p>\n<\/li>\n<li>\n<p>\u0412\u0441\u0435\u0433\u043e \u0431\u0443\u0434\u0435\u0442 \u043f\u0440\u043e\u0432\u0435\u0434\u0435\u043d\u043e log2(n) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0438 (log2(n) + 1) \u043e\u043f\u0435\u0440\u0430\u0446\u0438\u0439 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b (\u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044f\u044f \u043d\u0443\u0436\u043d\u0430, \u0447\u0442\u043e\u0431\u044b \u0443\u0431\u0435\u0434\u0438\u0442\u044c\u0441\u044f \u0432 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0441\u0442\u0438 \u0437\u0430\u043f\u0438\u0441\u0435\u0439).<\/p>\n<\/li>\n<li>\n<p>8 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 &#8212; 3 \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0438 4 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f<\/p>\n<\/li>\n<li>\n<p>16 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u043e\u0432 &#8212; 4 \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u0438 5 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<li>\n<p>1024 \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430 &#8212; 10 \u0441\u043b\u0438\u044f\u043d\u0438\u0439 \u0438 11 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u0439<\/p>\n<\/li>\n<\/ul>\n<h2>2. \u0415\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u044b\u0439 \u043c\u0435\u0442\u043e\u0434<\/h2>\n<p>\u041f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043c\u0435\u0442\u043e\u0434\u0430 \u043f\u0440\u044f\u043c\u043e\u0433\u043e \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u043d\u0435 \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442\u0441\u044f \u0432\u043e \u0432\u043d\u0438\u043c\u0430\u043d\u0438\u0435 \u0442\u043e, \u0447\u0442\u043e \u0438\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u0444\u0430\u0439\u043b \u043c\u043e\u0436\u0435\u0442 \u0431\u044b\u0442\u044c \u0447\u0430\u0441\u0442\u0438\u0447\u043d\u043e \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u043c, \u0442.\u0435. \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u0442\u044c <strong><em>\u0441\u0435\u0440\u0438\u0438<\/em><\/strong>.<\/p>\n<p><strong><em>\u0421\u0435\u0440\u0438\u044f &#8212; <\/em><\/strong>\u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u0430\u044f \u043f\u043e\u0434\u043f\u043e\u0441\u043b\u0435\u0434\u043e\u0432\u0430\u0442\u0435\u043b\u044c\u043d\u043e\u0441\u0442\u044c \u0437\u0430\u043f\u0438\u0441\u0435\u0439.<\/p>\n<p>\u041c\u0435\u0442\u043e\u0434 \u0435\u0441\u0442\u0435\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0433\u043e \u0441\u043b\u0438\u044f\u043d\u0438\u044f \u043e\u0441\u043d\u043e\u0432\u0430\u043d \u043d\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0438\u0439 \u043f\u0440\u0438 \u0440\u0430\u0441\u043f\u0440\u0435\u0434\u0435\u043b\u0435\u043d\u0438\u0438 \u0438 \u0438\u0445 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u043d\u0438\u0438 \u043f\u0440\u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u043c \u0441\u043b\u0438\u044f\u043d\u0438\u0438. \u0422. \u0435. \u0442\u0435\u043f\u0435\u0440\u044c \u043f\u0440\u0438 \u0441\u043b\u0438\u044f\u043d\u0438\u0438 \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u0440\u0430\u0431\u043e\u0442\u0430\u0442\u044c \u043d\u0435 \u0441 \u043f\u0430\u0440\u0430\u043c\u0438 \u043e\u0442\u0441\u043e\u0440\u0442\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0446\u0435\u043f\u043e\u0447\u0435\u043a, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0432\u0441\u0435\u0433\u0434\u0430 \u0438\u043c\u0435\u044e\u0442 \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u0443\u044e \u0434\u043b\u0438\u043d\u0443, \u0430 \u0441 \u043f\u0430\u0440\u0430\u043c\u0438 \u0441\u0435\u0440\u0438\u0439, \u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u0437\u0430\u0447\u0430\u0441\u0442\u0443\u044e \u043d\u0435 \u0431\u0443\u0434\u0443\u0442 \u043e\u0434\u0438\u043d\u0430\u043a\u043e\u0432\u044b \u043f\u043e \u0434\u043b\u0438\u043d\u0435.<\/p>\n<p>\u041d\u0430\u0447\u043d\u0451\u043c \u0441 \u0442\u043e\u0433\u043e \u0436\u0435, \u0441 \u0447\u0435\u0433\u043e \u043d\u0430\u0447\u0438\u043d\u0430\u043b\u0438 \u0432 \u043f\u0440\u043e\u0448\u043b\u044b\u0439 \u0440\u0430\u0437. \u0421 \u0441\u043e\u0437\u0434\u0430\u043d\u0438\u044f \u043a\u043b\u0430\u0441\u0441\u0430 \u043e\u0431\u044a\u044f\u0432\u043b\u0435\u043d\u0438\u044f \u043d\u0443\u0436\u043d\u044b\u0445 \u043f\u043e\u043b\u0435\u0439!<\/p>\n<pre><code class=\"cs\">public class NaturalOuterSort {     private string? _headers;     private readonly int _chosenField;     private readonly Type[] _columnOfTableTypes          = { typeof(int), typeof(string), typeof(DateTime) };     \/\/\u0412 \u044d\u0442\u043e\u043c \u0441\u043f\u0438\u0441\u043a\u0435 \u0431\u0443\u0434\u0443\u0442 \u0445\u0440\u0430\u043d\u0438\u0442\u044c\u0441\u044f \u0434\u043b\u0438\u043d\u044b \u0432\u0441\u0435\u0445 \u0441\u0435\u0440\u0438\u0439 \u0432 \u043e\u0431\u043e\u0438\u0445 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u0430\u0445     private readonly List&lt;int> _series = new();          public NaturalOuterSort(int chosenField)     {         _chosenField = chosenField;     } }<\/code><\/pre>\n<p>\u041e\u0442\u043b\u0438\u0447\u0438\u044f \u043e\u0442 \u043f\u0440\u0435\u0434\u044b\u0434\u0443\u0449\u0435\u0433\u043e \u0430\u043b\u0433\u043e\u0440\u0438\u0442\u043c\u0430 \u0441\u0440\u0430\u0437\u0443 \u0431\u0440\u043e\u0441\u0430\u044e\u0442\u0441\u044f \u0432 \u0433\u043b\u0430\u0437\u0430:<\/p>\n<ol>\n<li>\n<p> \u041f\u0440\u043e\u043f\u0430\u043b\u0438 \u043f\u043e\u043b\u044f _iterations \u0438 _segments, \u0442.\u043a. \u043c\u044b \u043d\u0435 \u043c\u043e\u0436\u0435\u043c \u0437\u0430\u0440\u0430\u043d\u0435\u0435 \u0437\u043d\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u044b \u0438 \u043a\u043e\u043b-\u0432\u043e \u0441\u0435\u0440\u0438\u0439.<\/p>\n<\/li>\n<li>\n<p>\u041f\u043e\u044f\u0432\u0438\u043b\u043e\u0441\u044c \u043f\u043e\u043b\u0435 _series, \u0432 \u043a\u043e\u0442\u043e\u0440\u043e\u043c \u0431\u0443\u0434\u0443\u0442 \u043b\u0435\u0436\u0430\u0442\u044c \u0434\u043b\u0438\u043d\u044b \u043d\u0430\u0448\u0438\u0445 \u0441\u0435\u0440\u0438\u0439<\/p>\n<\/li>\n<\/ol>\n<p>\u0414\u0430\u043b\u0435\u0435 \u0443 \u043d\u0430\u0441 \u043f\u043e \u0441\u043f\u0438\u0441\u043a\u0443 &#8212; \u043c\u0435\u0442\u043e\u0434 \u0440\u0430\u0437\u0431\u0438\u0435\u043d\u0438\u044f \u0437\u0430\u043f\u0438\u0441\u0435\u0439 \u043d\u0430 \u043f\u043e\u0434\u0444\u0430\u0439\u043b\u044b.<\/p>\n<pre><code class=\"cs\">private void SplitToFiles() {   using var fileA = new StreamReader(\"A.csv\");   _headers = fileA.ReadLine();            using var fileB = new StreamWriter(\"B.csv\");   using var fileC = new StreamWriter(\"C.csv\");   \/\/\u0441\u0447\u0438\u0442\u044b\u0432\u0430\u0435\u043c \u0441\u0442\u0440\u043e\u043a\u0443, \u043a\u043e\u0442\u043e\u0440\u0443\u044e \u0431\u0443\u0434\u0435\u043c \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0442\u044c \u0432 \u043f\u043e\u0434\u0444\u0430\u0439\u043b, \u0438 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0443\u044e \u0437\u0430 \u043d\u0435\u0439, \u0447\u0442\u043e\u0431\u044b    \/\/\u0441\u0440\u0430\u0432\u043d\u0438\u0442\u044c \u0438\u0445 \u0438 \u043f\u0440\u043e\u0432\u0435\u0440\u0438\u0442\u044c, \u0437\u0430\u043a\u043e\u043d\u0447\u0438\u043b\u0430\u0441\u044c \u0441\u0435\u0440\u0438\u044f \u0438\u043b\u0438 \u043d\u0435\u0442   string? firstStr = fileA.ReadLine();   string? secondStr = fileA.ReadLine();   bool flag = true;   int counter = 0;   while (firstStr is not null)   {     \/\/\u0414\u043e\u043f. \u0444\u043b\u0430\u0433 \u043d\u0443\u0436\u0435\u043d, \u0447\u0442\u043e\u0431\u044b \u043f\u0440\u0438 \u043e\u043a\u043e\u043d\u0447\u0430\u043d\u0438\u0438 \u0441\u0435\u0440\u0438\u0438 \u043d\u0435 \u043f\u043e\u0442\u0435\u0440\u044f\u0442\u044c \u043f\u043e\u0441\u043b\u0435\u0434\u043d\u044e\u044e \u0437\u0430\u043f\u0438\u0441\u044c \u0432 \u044d\u0442\u043e\u0439     \/\/\u0441\u0430\u043c\u043e\u0439 \u0441\u0435\u0440\u0438\u0438     bool tempFlag = flag;     if (secondStr is not null)     {       if (CompareElements(firstStr, secondStr))       {         counter++;       }       else       {         \/\/\u0415\u0441\u043b\u0438 \u0441\u0435\u0440\u0438\u044f \u043f\u0440\u0435\u0440\u0432\u0430\u043b\u0430\u0441\u044c, \u0442\u043e \u0437\u0430\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c \u0435\u0451 \u0434\u043b\u0438\u043d\u0443 \u0432 \u0441\u043f\u0438\u0441\u043e\u043a \u0438 \u043e\u0431\u043d\u0443\u043b\u044f\u0435\u043c \u0441\u0447\u0451\u0442\u0447\u0438\u043a         <\/code><\/pre>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-360222","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/360222","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=360222"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/360222\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=360222"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=360222"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=360222"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}