Skip to content Navigation Menu Toggle navigation Sign in Appearance settings PlatformAI CODE CREATIONGitHub CopilotWrite better code with AIGitHub Copilot appDirect agents from issue to mergeMCP RegistryNewIntegrate external toolsDEVELOPER WORKFLOWSActionsAutomate any workflowCodespacesInstant dev environmentsIssuesPlan and track workCode ReviewManage code changesAPPLICATION SECURITYGitHub Advanced SecurityFind and fix vulnerabilitiesCode securitySecure your code as you buildSecret protectionStop leaks before they startEXPLOREWhy GitHubDocumentationBlogChangelogMarketplaceView all featuresSolutionsBY COMPANY SIZEEnterprisesSmall and medium teamsStartupsNonprofitsBY USE CASEApp ModernizationDevSecOpsDevOpsCI/CDView all use casesBY INDUSTRYHealthcareFinancial servicesManufacturingGovernmentView all industriesView all solutionsResourcesEXPLORE BY TOPICAISoftware DevelopmentDevOpsSecurityView all topicsEXPLORE BY TYPECustomer storiesEvents & webinarsEbooks & reportsBusiness insightsGitHub SkillsSUPPORT & SERVICESDocumentationCustomer supportCommunity forumTrust centerPartnersView all resourcesOpen SourceCOMMUNITYGitHub SponsorsFund open source developersPROGRAMSSecurity LabMaintainer CommunityAcceleratorGitHub StarsArchive ProgramREPOSITORIESTopicsTrendingCollectionsEnterpriseENTERPRISE SOLUTIONSEnterprise platformAI-powered developer platformAVAILABLE ADD-ONSGitHub Advanced SecurityEnterprise-grade security featuresCopilot for BusinessEnterprise-grade AI featuresPremium SupportEnterprise-grade 24/7 supportPricing Search or jump to... Search code, repositories, users, issues, pull requests... Search Clear Search syntax tips Provide feedback We read every piece of feedback, and take your input very seriously. Include my email address so I can be contacted Saved searches Use saved searches to filter your results more quickly Name Query To see all available qualifiers, see our documentation. Sign in Sign up Appearance settings Resetting focus You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session. You switched accounts on another tab or window. Reload to refresh your session. Dismiss alert {{ message }} rp-code9 / programming Public Notifications You must be signed in to change notification settings Fork 1 Star 0 Code Issues 0 Pull requests 0 Actions Projects Security and quality 0 Insights Additional navigation options Code Issues Pull requests Actions Projects Security and quality Insights FilesExpand file tree masterBreadcrumbsprogramming/problems/sorting/Merge.javaCopy pathBlameMore file actionsBlameMore file actions Latest commit HistoryHistoryHistory54 lines (48 loc) · 1.47 KB masterBreadcrumbsprogramming/problems/sorting/Merge.javaCopy pathTopFile metadata and controlsCodeBlame54 lines (48 loc) · 1.47 KBRawCopy raw fileDownload raw fileOpen symbols panelEdit and raw actions123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354public class Merge { private static boolean less(Comparable a, Comparable b) { return a.compareTo(b) < 0; } private static void merge(Comparable[] a, Comparable[] aux, int low, int mid, int high) { for (int k = low; k <= high; ++k) { aux[k] = a[k]; } int i = low; int j = mid + 1; for (int k = low; k <= high; k++) { if (i > mid) { a[k] = aux[j++]; } else if (j > high) { a[k] = aux[i++]; } else if (less(a[j], a[i])) { a[k] = aux[j++]; } else { a[k] = aux[i++]; } } } private static void sort(Comparable[] a, Comparable[] aux, int low, int high) { if (low >= high) { return; } int mid = low + (high - low) / 2; sort(a, aux, low, mid); sort(a, aux, mid + 1, high); merge(a, aux, low, mid, high); } public static void sort(Comparable[] a) { Comparable[] aux = new Comparable[a.length]; sort(a, aux, 0, a.length - 1); } public static void print(Object[] array) { for (Object a: array) { System.out.print(a + " "); } System.out.println(""); } public static void main(String[] args) { String[] array = {"Hope", "Eve", "Alice", "Charlie", "Tom", "Bob"}; Merge.print(array); Merge.sort(array); Merge.print(array); }} You can’t perform that action at this time.