VoyForums
[ Show ]
Support VoyForums
[ Shrink ]
VoyForums Announcement: Programming and providing support for this service has been a labor of love since 1997. We are one of the few services online who values our users' privacy, and have never sold your information. We have even fought hard to defend your privacy in legal cases; however, we've done it with almost no financial support -- paying out of pocket to continue providing the service. Due to the issues imposed on us by advertisers, we also stopped hosting most ads on the forums many years ago. We hope you appreciate our efforts.

Show your support by donating any amount. (Note: We are still technically a for-profit company, so your contribution is not tax-deductible.) PayPal Acct: Feedback:

Donate to VoyForums (PayPal):

Login ] [ Contact Forum Admin ] [ Main index ] [ Post a new message ] [ Search | Check update time ]


[ Next Thread | Previous Thread | Next Message | Previous Message ]

Date Posted: 15:07:09 03/05/02 Tue
Author: Hjálmtýr
Subject: Re: Linked list - remove item
In reply to: 's message, "Linked list - remove item" on 08:32:06 03/05/02 Tue

>Afhverju getur þetta fall ekki fjarlægt seinasta
>stakið úr listanum. Það er eins og að það se ekki til!
>
>hvað er vitlaust í þessu:
>
>
>int remove(node *x, node *target)
>{
>while(x->next != NULL) {
> if(x->next == target) {x->next= x->next->next; delete
>target; return 0; }
>
> x = x->next;
> }
>
> return -1;
>}

Þegar þú segir "seinasta stakið", þá áttu við þegar aðeins er einn hnútur eftir, er það ekki? Ég sé ekki annað en
að þetta virki til að fjarlægja AFTASTA stakið úr listanum.

Þessi kódi virkar bara til að taka út hnút úr lista sem hefur haushnút (þ.e. dummy hnút fremst). Annars geturðu
ekki tekið út fremsta hnútinn, því að ef x bendir beint á hann þá verður skilyrðið " x->next == target " aldrei
satt. Því þá er " x == target ". Það verður því að nota haushnút til að x geti alltaf bent á hnútinn FYRIR FRAMAN
hnútinn sem target bendir á.

[ Next Thread | Previous Thread | Next Message | Previous Message ]

Post a message:
This forum requires an account to post.
[ Create Account ]
[ Login ]
[ Contact Forum Admin ]


Forum timezone: GMT-8
VF Version: 3.00b, ConfDB:
Before posting please read our privacy policy.
VoyForums(tm) is a Free Service from Voyager Info-Systems.
Copyright © 1998-2019 Voyager Info-Systems. All Rights Reserved.