Wednesday, July 8, 2020

C++ Code Creates Class Of List Needed To Be Updated - 275 Words

C++ Code Creates Class Of List Needed To Be Updated (Coursework Sample) Content: #includeusing namespace std;#includeclass Node{public: int get(){return object;} ;//void set(int object){this-object=object;};Node*getNext(){return nextNode;};void setNext(Node *nextNode){this-nextNode=nextNode;};private: int object;Node*nextNode;};//the list classclass List{public:List();void add(int addObject);int get();bool next();friend void traverse(List list);friend List addNodes();void addProgram();private:int size;Node*headNode;Node*currentNode;Node*lastCurrentNode;};//constructor implementationList::List(){headNode=new Node();headNode-setNext(NULL);currentNode=NULL;lastCurrentNode=NULL;size=0;}//add() class method implementationvoid List::add(int addObject){Node*newNode=new Node();newNode-set(addObject);if(currentNode!=NULL){newNode-setNext(newNode-getNext());currentNode-setNext(newNode);lastCurrentNode=currentNode;currentNode=newNode;}else{newNode-setNext(NULL);headNode-setNext(newNode);lastCurrentNode=headNode;currentNode=newNode;}size++;}//get classmethod int List::get(){if(currentNode!=NULL)return currentNode-get();}//next() class methodbool List::next(){if(currentNode==NULL)return false;lastCurrentNode=currentNode;currentNode=currentNode-getNext();if(currentNode==NULL||size==0)return false;elsereturn true;}//friend function to treverse linked list