Two convergence intersection with fast sorting

Source: Internet
Author: User

1. Main program%%find two sets quick sort TicarrayList1= [ the, -, $, the, the, -, -, the, -, the];arraylist1= QuickSort (ArrayList1,1, Length (arrayList1)); ArrayList2= [ the, the, the, -, at,566, the];arraylist2= QuickSort (ArrayList2,1, Length (arrayList2));%%two sets of intersection; Length_arraylist1=length (arrayList1); Length_arraylist2=length (ARRAYLIST2); Union=[];i=1; J=1; while true    ifI < Length_arraylist1 && J <Length_arraylist2ifArrayList1 (i) <ArrayList2 (j) I= i +1; ElseIf ArrayList1 (i)>ArrayList2 (j) J= j +1; ElseUnion=[Union,arraylist1 (i)]; I= i +1; J= j +1; EndElse         Break; ENDENDTOC Quick Sort functions function arrayList=QuickSort (Arraylist,low,high)% Pivotpos =1;if(Low <High ) [Pivotpos,arraylist]=partition (Arraylist,low,high); ArrayList= QuickSort (Arraylist,low,pivotpos-1); ArrayList= QuickSort (Arraylist,pivotpos +1, high); EndEnd partition function; functions [low,new_arraylist]=partition (Arraylist,low,high)ifNargin = =1 Low=1; High=length (arrayList); Endpivot= ArrayList (low); %using the 1th record of the interval to make the benchmark; whileThe low < high% is scanned from the interval two stages to the middle until low =Hing whileLow Pivot High= High-1; EndifLow < high% means found arraylist[hihg]<pivot; Temp=arrayList (Low); ArrayList (Low)=arrayList (high); ArrayList (High)=temp; Low= Low +1; End whileLow < High && arrayList (low) <=Pivot Low= Low +1; EndifLow <High temp=arrayList (high); ArrayList (High)=arrayList (Low); ArrayList (Low)=temp; High= High-1; Endendnew_arraylist=Arraylist;end

Find out what the faster way to solve the set intersection.

Two convergence intersection with fast sorting

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.