Partition adjustment of the array of algorithm summary

Source: Internet
Author: User

Given an ordered array of arr, adjust arr so that the left half of the array does not have repeating elements and ascending, and does not guarantee that the right is ordered

The partition is OK. The U-Zone is non-repeating and the ascending U is the last position of this region, the initial u=0

I do a left-to-right traversal, and on arr[u+1....i] there is no guarantee that there are no duplicate elements and that the ascending area I is the last position of this area

I move to the right because the array is ordered as a whole, if arr[i]!=arr[u] indicates that the current arr[i] should be added to the U area then exchange it! If Arr[i]==arr[u] indicates the value of the current number Arr[i] has been added to the U area before

On the code:

 PackageTT; Public classTest81 { Public voidLeftunique (int[] arr) {                if(arr==NULL|| Arr.length<2){             return; }        intU = 0; intI =1;  while(I! =arr.length) {            if(arr[i++]!=Arr[u]) {Swap (arr,++u, I-1); }        }            }        }

Partition adjustment of the array of algorithm summary

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.