Array--merge two ordered arrays, a, a, into a new ordered array C

Source: Internet
Author: User

There are two ordered arrays, a, B, and the lengths are m,n; use an algorithm with a time complexity of m+n to merge the two arrays into an ordered array of C.

1 Static voidMain (string[] args)2         {3             int[] A = {1,3,5,6,6,7, - };4             int[] B = {2,3,4,6,7, -, -, - };5 6             varClength = A.length +b.length;7             int[] C =New int[clength];8             inti =0, j =0, k =0;9 Ten              for(i =0, j =0, k =0; (I < A.length | | J < b.length) && K < (a.length + b.length); i++, J + +, k++) One             { A                 if(i>=a.length) -                 { -C[K] =B[j]; the                     Continue; -                 } -  -                 if(J >=b.length) +                 { -C[K] =A[i]; +                     Continue; A                 } at  -                 if(A[i] >B[j]) -                 { -C[K] =B[j]; -i--; -                 } in                 Else -                 { toC[K] =A[i]; +j--; -                 } the             } *  $              for(intL =0; L < C.length; l++)Panax Notoginseng             { - System.Console.Write (C[l]); the             } +  A System.Console.Read (); the}

This is, soon to a company encountered a problem, in fact, this understanding of the meaning of the topic, think carefully about the logic, or do it. May just start to do when a little nervous, the most afraid of the pen test company,

Too long did not take a pen to write, look at the crooked handwriting is uncomfortable, write a mess! Fortunately, to the interviewer to express the logic of clear!

Seems to need to calm down, practice the word! The Spring Festival is coming soon, happy Spring! I hope to be able to further my life and career in the 2015.

Fighting for me,my Dear Darling,my family, ~o (∩_∩) o~.

Array--merge two ordered arrays, a, a, into a new ordered array C

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.