/**************************************************************** * Engineering 4892 Data Structures * Assignment: 4 Question 2 Date Due: July 5th/2001 * Name: Daryl Martin * Student #: 9713520 * Username: darylm *****************************************************************/ #include "BigNatR.h" /***************************************************************** * makeList - Create a linked list containing the digits in r * as your data * * Post: Result = head of the list representing r *****************************************************************/ Node* BigNat::makeList(unsigned long r) { int data = 0; data = r % 10; //pick the last digit off the value r r = r/10; //drop the last digit off the value r Node* toAdd = new(std::nothrow) Node; //create our new node if(toAdd != 0) { //if there is memory than... toAdd->digit = data; //store the data in the node toAdd->next = makeList(r); //recursive function call err = Ok; } else {err = NewFail;} } /***************************************************************** * makeULong - Converts the list to an unsigned long integer * * Post: err = Ok -> Result = D converted to an unsigned long * err = Overflow <-> D is too big for an unsigned long *****************************************************************/ unsigned long BigNat::makeULong(const Node *l) const { unsigned long result = 0; if(l != 0 && err != Overflow) { unsigned long add = makeULong(l->next); result = l->digit + 10*add; if(result < add){ err = Overflow;} //Given post condition } return result; }