Cov txheej txheem:

Yuav ua li cas koj ntxiv node rau ib daim ntawv txuas?
Yuav ua li cas koj ntxiv node rau ib daim ntawv txuas?

Video: Yuav ua li cas koj ntxiv node rau ib daim ntawv txuas?

Video: Yuav ua li cas koj ntxiv node rau ib daim ntawv txuas?
Video: Kav Tsij Ua Hluas Koj Txiv - Qab Zib nkauj tawm tshiab 2023 2024, Kaum ib hlis
Anonim

Ntxig ib qho ntawm ib txoj haujlwm tshwj xeeb hauv cov npe txuas

  1. Hla mus Txuas daim ntawv teev npe mus rau txoj hauj lwm-1 nodes .
  2. Ib zaug txhua txoj haujlwm - 1 nodes yog traversed, faib lub cim xeeb thiab cov ntaub ntawv muab rau tus tshiab node .
  3. taw tes tus taw tes tom ntej ntawm qhov tshiab node mus rau tom ntej ntawm tam sim no node .
  4. taw tes tus pointer tom ntej ntawm tam sim no node mus rau qhov tshiab node .

Ntawm no, ua li cas koj ntxiv ib yam dab tsi rau ib daim ntawv txuas?

Cov txheej txheem ntawm LinkedList chav kawm:

  1. boolean add(Object item): Nws ntxiv cov khoom tom kawg ntawm daim ntawv.
  2. void add(int index, Object item): Nws ntxiv ib yam khoom ntawm qhov muab index ntawm daim ntawv.
  3. boolean addAll(Collection c): Nws ntxiv tag nrho cov ntsiab lus ntawm cov teev sau c rau hauv daim ntawv.

qhov twg yog qhov tshiab node ntxiv rau cov npe txuas? Cov nov node yog ib txwm ntxiv tom qab kawg node ntawm qhov muab Linked List . Piv txwv li yog tias muab Linked List yog 5-> 10-> 15-> 20-> 25 thiab peb ntxiv ib yam khoom 30 thaum kawg, ces tus Linked List ua 5->10->15->20->25->30.

Kuj Paub, Kuv yuav ua li cas ntxiv ib qho ntawm qhov kawg ntawm cov npe txuas?

Cov kauj ruam los ntxig rau ntawm qhov kawg ntawm Singly linked list

  1. Tsim cov node tshiab thiab xyuas kom meej tias qhov chaw nyob ib feem ntawm qhov tshiab node taw qhia rau NULL i.e. newNode->next=NULL.
  2. Hla mus rau qhov kawg ntawm cov npe sib txuas thiab txuas lub kawg ntawm cov npe nrog cov node tshiab, piv txwv li lub xeem node tam sim no taw tes rau qhov tshiab.

Koj txheeb cov npe txuas li cas?

Yuav ua li cas txheeb cov npe txuas nrog kev sib koom ua ke

  1. Yog tias: Daim ntawv teev npe muaj ib lossis tsawg dua, rov qab rau tib daim ntawv teev npe.
  2. Lwm yam: Faib cov npe rau hauv ib nrab siv cov kev faib ua haujlwm.
  3. Sort: Sort ?ob ob halves ntawm daim ntawv.
  4. Thaum kawg, ua ke cov npe txheeb.

Pom zoo: