Compare two ordered sets

Source: Internet
Author: User

Application scenario (Exchange depth increment push)

    1. [[411.8,6],[411.75,11],[411.6,22],[411.5,9],[411.3,16]]
    2. [[411.8,5],[411.7,11],[411.5,22],[411.5,9],[411.3,1]]
ImportJava.util.ArrayList;ImportJava.util.List; Public  class  a {     Public Static void Main(string[] args) {/** * Two sets are ordered, from large to small * 1). The collection now has a collection of old no, add * * 2). Collection now there's a collection of all that is present, discard * * 3). The collection now does not have but the collection old has, the quantity flag bit 0 * * 4). The collection now has a set of existing but inconsistent changes in number.        //string[] Length is 2 The first data is price, the second data is the quantityList<string[]> now =NewArraylist<string[]> (); list<string[]> old =NewArraylist<string[]> (); StringBuilder data =NewStringBuilder ();//For stitching the final data        intOldsize = Old.size ();intNowsize = Now.size ();intindex =0;//Now Collection index        intLast_index =0;//Old collection index         for(inti =0, size = Oldsize + nowsize; i < size; i++) {if(Last_index >= oldsize && index >= nowsize) {//If each element of two data is consistent                 Break; }DoublePrice =-1D String amount ="";if(Index < Nowsize) {Price = Double.parsedouble (Now.get (index) [0]); Amount = Now.get (index) [1]; }DoubleLastprice =-1D String Lastamount ="";if(Last_index < Oldsize) {Lastprice = double.parsedouble (Old.get (Last_index) [0]); Lastamount = Old.get (Last_index) [1]; }if(Price = = Lastprice) {if(!amount.equals (Lastamount)) {Data.append ("["+ Price +","+ Amount +"],");                } last_index++;            index++; }Else if(Price > Lastprice) {Data.append ("["+ Price +","+ Amount +"],");            index++; }Else if(Price < Lastprice) {Data.append ("["+ Price +","+0+"],");            last_index++; }        }    }}

Compare two ordered sets

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.