I've been working on some project code and the project is basically to read in a file that has contacts in it, put the data into nodes, put those nodes into a list, remove the duplicates and then print out the list. I have done this.
Now, I need to get all the duplicates that were removed and output them (Like, "The contacts that were deleted are: " )
I don't really know where to start. Anytime I run it, it prints out the address (it prints something like 0xf9000).
I would appreciate some guidance or help. Here's where I'm trying to implement it:
void purge(List &L){
//ElementType fir, midd, las, phon;
//List R;
vector<NodePointer> duplic;
NodePointer p, q, pQ;
int counter = 0;
p = L.getFirst();
while(p != nullptr){
q = p->getNext();
while( q != nullptr){
if(p->sameAs(q) == true){
counter++;
pQ = q;
q = q->getNext();
//The vector duplic is my attempt to push the value into the vector so I can print it out
duplic.push_back(pQ);
L.remove(pQ);
}
else
q = q->getNext();
}
p = p->getNext();
}
cout << "The number of deleted duplicates are: " << counter << endl;
for(int i = 0; i < duplic.size(); i++){
cout << duplic.at(i);
cout <<endl;
}
}
for(int i = 0; i < duplic.size(); i++){
cout << duplic.at(i)->printNode();
cout <<endl;
}
> typedef Node* NodePointer;
This more often than not only serves to obscure things rather than inform.
Like not being reminded that the thing you have is really a pointer, and that you need to dereference it to get anywhere.