Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

You can represent an integer with any number of digits by storing the integers a

ID: 3631261 • Letter: Y

Question

You can represent an integer with any number of digits by storing the integers as a linked list of digits. A more efficient representation will store a larger integer in each node. Design and implement a class for whole number arithmetic in which a number is implemented as a linked list of integers. Each node will hold an integer less than or equal to 999. The number represented is the concatenation of the numbers in the nodes. For example, if there are four nodes with the four integers 23, 7, 999, and 0 then this is represents the number 23, 007, 999,000. Note that the number in a node is always considered to be three digits long. If it is not three digits long, then leading zeros are added to make it three digits long. Overload all the usual integer operators to work with your new class.

Explanation / Answer

Dear Friend here is the class and a test for it PLEASE RATE #include using namespace std; struct nodeType { int info; nodeType *link; }; class linkedListType { public: linkedListType() { head=new nodeType; head=0; } ~linkedListType() { destroyList(); } void insertFirst(int val) { nodeType *c; c=new nodeType; c->info=val; c->link=0; if(head==0) head=c; else { c->link=head; head=c; } } void insertLast(int val) { nodeType *p; p=new nodeType; p->info=val; p->link=0; if(head==0) head=p; else { nodeType *c; c=new nodeType; c=head; while(c->link!=0) c=c->link; c->link=p; } } void insertAfter(int loc,int val) { int count=0; nodeType *p; p=new nodeType; p->info=val; p->link=0; if(head==0) head=p; else { nodeType *c; c=head; while(countlink!=0) { c=c->link; count++; } if(loc>count) return; else { p->link=c->link; c->link=p; } } } void insertBefore(int loc,int val) { if(locinfo=val; p->link=0; if(head==0) head=p; else { nodeType *c=head; while(countlink; count++; } p->link=c->link; c->link=p; } } void initializeList() { destroyList(); } void destroyList() { nodeType *q; while(head!=0) { q=head; head=head->link; delete q; } } bool isEmpty() { return (head == 0); } void print() { nodeType *curent=head; if(head!=0) { coutlink; while(curent != NULL) { coutlink; head=p; while(c!=0) { p->link=new nodeType; p=p->link; p->info=c->info; p->link=0; c=c->link; } } } }; int main() { linkedListType obj1; obj1.insertFirst(23); obj1.insertLast(7); obj1.insertAfter(1,999); obj1.insertLast(0); obj1.print(); }
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote