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: 09:25:20 03/07/02 Thu
Author: Hjálmtýr
Subject: Re: fallið gefa
In reply to: 's message, "fallið gefa" on 08:35:08 03/07/02 Thu

>ég er með fallið void
>gefa(node *p,STACK s, int fjoldi)
>{
> for (int i = 0; inext)
> p->next = new node(s.pop(), p->next);
>
>}
>skilgreint í struct node og svo geri ég
>gefa(headt,stokkur,5);
>gefa(headn,stokkur,5);
>í main fallinu en listinn sem hausahnúturinn headn
>bendir á fær sömu spilin og headt bendir á. Af hverju
>er stokkurinn óbreyttur eftir gefa aðferðina? Það er
>eins og stokkur gefi spilin og taki þau svo til baka
>og lætur næsta fá sömu spil.

Til þess að stokkurinn breytist þarft hann að vera sendur inn sem tilvísunarviðfang. Rétti hausinn á fallinu er:

void gefa( node *p, STACK<Spil> &s, int fjoldi )

Þar sem þú notar greinilega haushnúta, þá þarf hnútabendirinn p ekki að vera tilvísunarviðfang, þar sem
þú breytir honum ekki, heldur því sem hann bendir á, þ.e. haushnútnum. Ef þú notaðir ekki haushnúta, þá þyrfti p
líka að vera tilvísunarviðfang (kæmi "node *&p" í stað "node *p").

[ 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.