Cov txheej txheem:

Kuv yuav txheeb cov npe sib txuas li cas ntawm cov tsiaj ntawv?
Kuv yuav txheeb cov npe sib txuas li cas ntawm cov tsiaj ntawv?

Video: Kuv yuav txheeb cov npe sib txuas li cas ntawm cov tsiaj ntawv?

Video: Kuv yuav txheeb cov npe sib txuas li cas ntawm cov tsiaj ntawv?
Video: Saib Mis paub Poj niam (hluas nkauj) tus yam ntxwv lub siab 2024, Tej zaum
Anonim

Kev txheeb ib txoj hlua LinkedList hauv Java yog ib qho yooj yim. Koj ua tau xaiv txoj hlua LinkedList hauv ascending cov tsiaj ntawv xaj los ntawm kev siv xaiv ( Sau npe ) Koj tuaj yeem ua tau xaiv txoj hlua LinkedList hauv nqis cov tsiaj ntawv xaj los ntawm kev siv xaiv ( Sau npe , Sib piv c).

Ua raws li qhov no hauv kev txiav txim siab, koj yuav txheeb cov npe txuas li cas?

Hauv qab no yog qhov yooj yim ntxig xaiv algorithm rau linked lis . 1) Tsim ib qho khoob txheeb (los yog tshwm sim) lis 2) Hla qhov muab lis , ua raws li rau txhua qhov node. a) Ntxig tam sim no rau hauv txheeb txoj hauv kev txheeb los yog tshwm sim lis . 3) Hloov lub taub hau ntawm muab linked lis mus taub hau txheeb (los yog tshwm sim) lis.

Tom qab ntawd, lo lus nug yog, koj yuav txheeb cov npe txuas hauv CPP li cas? C ++ Program los ua kom tiav Sorted Singly Linked List

  1. * C ++ Program los siv cov npe sib txuas ib leeg.
  2. # suav nrog
  3. # suav nrog
  4. # suav nrog
  5. struct node.
  6. cov ntaub ntawv;
  7. node * tom ntej;
  8. }*p = NULL, *head = NULL, *q = NULL, * np = NULL;

Tsis tas li lo lus nug yog, koj yuav txheeb xyuas cov npe txuas nrog siv npuas hom li cas?

Txhawm rau ua npuas, peb ua raws cov kauj ruam hauv qab no:

  1. Kauj Ruam 1: Xyuas seb cov ntaub ntawv ntawm 2 qhov nyob ib sab yog nyob rau hauv qhov kev txiav txim nce los yog tsis. Yog tias tsis yog, sib pauv cov ntaub ntawv ntawm 2 qhov chaw nyob ib sab.
  2. Kauj Ruam 2: Thaum kawg ntawm kev hla 1, cov khoom loj tshaj plaws yuav yog qhov kawg ntawm daim ntawv.
  3. Kauj ruam 3: Peb txiav lub voj, thaum tag nrho cov ntsiab lus pib.

Koj txheeb cov npe txuas hauv Java li cas?

sortList() yuav txheeb cov nodes ntawm cov npe nyob rau hauv ascending order

  1. Txhais lub node tam sim no uas yuav taw tes rau lub taub hau.
  2. Txhais lwm qhov index uas yuav taw tes rau ntawm ib sab ntawm tam sim no.
  3. Sib piv cov ntaub ntawv tam sim no thiab index node.
  4. Tam sim no yuav taw tes rau tam sim no.
  5. Txuas ntxiv cov txheej txheem no kom txog thaum tag nrho cov npe raug txheeb xyuas.

Pom zoo: