#explanation on the logic

24 messages · Page 1 of 1 (latest)

fast coralBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

pearl quarry
#

im confused as to why the strcmp statement goes through if previous and current both point to the same place, with the condition being if theyre NOT the same

latent wagon
#

strcmp does a alpha sort of chars.. <0 means arg1 was less then arg2 (alphabetically)

pearl quarry
#

yes!! but i dont understand the previous part, where it says if(current != previous)... bc i set previous and current both to the head prior to the dowhile loop

latent wagon
#

if current == previous, then that if() never runs it's body

pearl quarry
#

yes but why! since theyre both pointing to the same place?
like if head was "name"
theyre both pointing to name, so how could they be different?

latent wagon
#

you have two "name"'s ?!

#

what is your actual C++ syntax question ?

#

or are you asking why your algo doesn't work?

pearl quarry
#

it works! im just confused abt why it does-- let me write my question visually to better explain

latent wagon
#

cout << uintptr_t(current)

#

know you know how to output ptr values.

#

does that help?!

#

cout << current->data.name; now you can display the content of that..

#

do that pre-strcmp.. now you can see what is about to occur

#

cout << uintptr_t(current) and cout << uintptr_t(previous) just before that if

pearl quarry
#

if *current and previous

latent wagon
#

prove it

pearl quarry
#

that didnt help bc theyre the same numbers

#

im not very good at pointers and nodes yet, so im just wondering how it differentiates between them, and why they wouldnt be the same thing.

latent wagon
#

are you claiming that ptr1 with a value of (lets say) 100, and ptr2 with the same value correctly executes if( ptr1 != ptr2 ) ? cause that would make most of the software in the world be wrong.

pearl quarry
#

i have no idea but thats alright i just do not think i will understand this way. ill just figure it out another time after more research

#

!solved

fast coralBOT
#

Thank you and let us know if you have any more questions!