### I'm So Confused

This Whole Example is Confusing me to much Especially at Line 59
current_node = new_node; if current Node is = to New Node then the current Must Have the Value of the New for example if new node's Value is 6 the current node should have 6 that's not an error i just want an explanation Please Explain it
 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128`` ``````#include #include #include using namespace std; class Node{ public: int getn() { return object; } void setn(int obj) { this->object = obj; } Node* getnex() { return Next_node; } void setnext(Node *Next_node) { this->Next_node = Next_node; } private: int object; Node* Next_node; }; class list{ public: void add(int); int get(); bool next(); friend void traverse(list List); friend list addnodes(); list() { head_node = new Node(); head_node->setnext(NULL); current_node = NULL; size = 0; } private: int size; Node* current_node; Node* head_node; Node* last_current_node; }; void list::add(int obj) { Node* new_node = new Node(); new_node->setn(obj); if(current_node != NULL) { new_node->setnext(current_node->getnex()); current_node->setnext(new_node); last_current_node = current_node; current_node = new_node; } else { new_node->setnext(NULL); head_node->setnext(new_node); last_current_node = head_node; current_node = new_node; } size++; } int list::get() { if(current_node!=NULL) { return current_node->getn(); } } bool list::next() { if(current_node == NULL) { return false; } last_current_node = current_node; current_node = current_node->getnex(); if(current_node == NULL || size == 0) { return false; } else { return true; } } void traverse(list List) { Node* saved_C_node = List.current_node; List.current_node = List.head_node; for(int i = 1;List.next();i++) { cout<<"\n Elements: "<
current_node is a pointer, like a note with an address. You changing it to point to new_node, like writing down new address of your friend, who have moved
linked list is so confusing. You really need a board and draw your nodes list and the node itself. Keep tracking each node.
Topic archived. No new replies allowed.