Algorithm 5--sort--merge Sorted Array

Source: Internet
Author: User

A few days ago in busy other things, no time to update, today updated a few, although there are several SMR blog temporarily not open, has been written well, will slowly open later

Update an algorithmic question about sorting today

1 Merge Sorted Array
Describe
Given sorted integer arrays A and B, merge B into a as one sorted array.
Note:you may assume a have enough space to hold additional elements from B. The number ofelements initialized in A D B is M and N respectively.
1#include <stdio.h>2 3 4 voidMergetwosort (intA[],intMintB[],intN)5 {6     intlen1=m-1;7     intlen2=n-1;8     intlen3=m+n-1;9      while(len1>=0&&len2>=0)Ten     { OneA[LEN3--]=A[LEN1]&GT;B[LEN2]? a[len1--]:b[len2--]; A     } -      while(len2>=0) -     { thea[len3--]=b[len2--]; -     } - } -  + intMain () - { +     inta[4]={1,2,4,9}; A     intb[7]={1,3,4,5,7,8,9}; atMergetwosort (A,4B7); -      for(inti =0; I < One; i++) -     { -printf"%d", A[i]); -     } -     return 0; in}

Algorithm 5--sort--merge Sorted Array

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.