Koj txheeb TreeSet li cas?
Koj txheeb TreeSet li cas?

Video: Koj txheeb TreeSet li cas?

Video: Koj txheeb TreeSet li cas?
Video: Mam Yuav Koj Tej Txheeb Ze { COVER 2023 } Paj Zoo Vaj Nkauj Zoo Mloog 2023 2024, Kaum ib hlis
Anonim

Cov TreeSet kev siv yog kev xaiv los ntawm kev txiav txim lexicographic ntawm txoj hlua qhov tseem ceeb koj ntxig. Yog koj xav tau xaiv los ntawm tus nqi pes tsawg, tom qab ntawd koj yuav tsum ua raws li cov lus qhia no thiab tsim ib qho khoom tshiab thiab hla txoj kev sib piv rau, lossis siv koj tus kheej sib piv.

Ib yam li ntawd, TreeSet tswj hwm li cas?

Cov TreeSet siv lub NavigableSet interface los ntawm kev txais cov chav kawm AbstractSet. TreeSet siv qhov SortedSet interface kom duplicate qhov tseem ceeb yog tsis pub. Cov khoom hauv a TreeSet yog khaws cia nyob rau hauv ib tug sorted thiab ascending xaj . TreeSet ua tsis yog khaws cia qhov ntxig xaj ntawm cov khoom tab sis cov ntsiab lus yog txheeb los ntawm cov yuam sij.

Qhov thib ob, koj yuav txheeb qhov array siv TreeSet li cas? Ascending Order: siv TreeSet , los ntawm dhau ArrayList cov ntsiab lus raws li kev sib cav rau inter-conversion constructor. Kev txiav txim nqis los: siv TreeSet , los ntawm siv Comparator interface thiab muab thim rov qab kev xaiv logic thiab thaum kawg ntxiv tag nrho cov ntsiab lus ntawm ArrayList rau TreeSet siv addAll() method of Collection interface.

Nyob rau hauv txoj kev no, koj yuav txheeb TreeSet li cas hauv nqe lus nug?

Rau txheeb TreeSet hauv kev txiav txim siab , siv descendingSet() txoj hauv kev Java. Txoj kev descendingSet() yog siv los xa rov qab a rov qab txiav txim saib ntawm cov khoom uas muaj nyob rau hauv cov teeb no.

Dab tsi sorting algorithm yog siv hauv TreeSet?

Cov TreeSet chav kawm sab hauv siv TreeMap los khaws cov khoom. Cov ntsiab lus hauv a TreeSet raug txheeb raws li lawv qhov kev txiav txim. Koj tseem tuaj yeem muab tus neeg sib piv kev cai rau tus TreeSet thaum lub sij hawm tsim los cia nws xaiv cov khoom raws li cov khoom sib piv.

Pom zoo: