Jump to content
bxx

Intrebare C

Recommended Posts

Salut, am un examen la SDA (Structuri de Date si Algoritmi) si toate bune si frumoase, doar ca nu inteleg o chestie.

Am urmatoarea linie:

elementCurent->pointerAnteriorElement->pointerUrmatorulElement = elementCurent->pointerUrmatorulElement;

Pointerii sunt definiti in structura:

typedef int info;
typedef struct element{
info informatie;
element *pointerUrmatorulElement;
element *pointerAnteriorElement;
} pelement;

Nu inteleg ce inseamna linia respectiva, adica de ce sunt doua "->" si ce reprezinta acest lucru.

Ma poate lamuri cineva? Multumesc!

Link to comment
Share on other sites

. are prioritate mai mare decat *, deci compilatorul intai iti trateaza .-ul, dupa iti dereferentiaza (sper ca am tradus in romglish corect) pointerul. -> face trimitere la un camp al unui tip de date spre care indica un pointer

pentru doua -> urmezi logica pointer1->pointer2->date , pointer2 fiind fiind un camp de date inclus in structura spre care indica pointer1, iar "date" e un camp de date al tipului spre care indica pointer2

LE: Muie! 10 topicuri sau mars pe cppreference si pune mana pe carte

Edited by Patrunjel
Link to comment
Share on other sites

elementCurent->pointerAnteriorElement este de fapt adresa luielementAnterior

deci:

elementCurent->pointerAnteriorElement->pointerUrmatorulElement e tot una cu elementulAnterior->pointerUrmatorulElement

Practic schimbi pointerul spre urmatorul element din elementulAnterior SPRE elementul urmator al elementului curent ... cu alte cuvinte: elementul anterior va indica spre elementul urmator, iar elementul curent va fi exclus din lista asta

Astfel de structuri se pot intelege foarte usor daca iti faci un mic desen pe perete ;)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



×
×
  • Create New...