Linked List question, pointer comparasion.

ptr->getNext() == entry_ptr
can someone tell me how this is being compared?
I know that pointer are compared with addresses.
I just need confirmation of my knowledge.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
bool LinkedBag<T>::remove(const T& an_entry);
//Singly Linked List to retain order

Node<T>* entry_ptr = getPointerTo(an_entry);
Node<T>* ptr = head_ptr; //start from the head ptr
while(ptr != nullptr) //Traverse through the singly linked list
{
	if(ptr->getNext() == entry_ptr) //FROM THE PREVIOUS NODE of the node we want to remove,
	{                                         //we will see if the next node is the node we want to remove
		//Algoritm; The previous node will call the entry_ptr getNext and set it with the previous node's getNext()
		ptr->setNext(entry_ptr->getNext());
		//REMEMBER THESE 3 LINES; THIS IS HOW YOU REMOVE AN NODE!!!!
		entry_ptr->setNext(nullptr);
		delete entry_ptr;
		entry_ptr = nullptr;
                return true;
	}
        return false;
}
Last edited on
they are compared as if integers, usually of the machine's word size, eg 64 bit PC compares 2 64 bit integers (unsigned).

yes, it is comparing the addresses. It is saying "are these two pointers pointing to the same location in memory".
Topic archived. No new replies allowed.