#if 1 #include #include using namespace std; struct Node { double data; Node *next; }; void add2front(Node *&list, double value); void printList(Node *list); void printListRecursive(Node* list); double calcSum(Node *list); double findMin(Node *list); Node* findMatchingNode(Node *list, double key); void add2back(Node * &list, double newVal); int main() { // make an empty list Node *list; list = NULL; // add some things to list add2front(list, 3.14); add2front(list, 7.0); add2front(list, 13.5); add2front(list, 12.4); // print the list cout << "List using non-recursive print: "<data = value; // (*temp).data = value; temp->next = list; //make the list to point to new node list = temp; } // Prints all the data in the list void printList(Node *list) { Node* temp; temp = list; //point to the first element /* cout << temp->data << endl; //print 1st temp = temp->next; cout << temp->data << endl; //print 2nd temp = temp->next; cout << temp->data << endl; // print3rd */ //shorter version - works for any length cout << "Print using while " << endl; while(temp != NULL) { cout << temp->data << endl; temp = temp->next; } //using for cout << "Print using for " << endl; for(Node* temp = list; temp != NULL; temp = temp->next) { cout << temp->data << endl; } } // Returns the sum of all the elements in the list double calcSum(Node *list) { double sum = 0; //using for for(Node* temp = list; temp != NULL; temp = temp->next) { sum = sum + temp->data; } return sum; } // Returns the minimum value in the list // Assumes list is not empty! double findMin(Node *list) { double min = list->data; for(Node* temp = list; temp!=NULL; temp = temp->next) { if(temp->data < min) { min = temp->data; } } return min; } Node* findMatchingNode(Node *list, double key) { return NULL; } void add2back(Node * &list, double newVal) { } void printListRecursive(Node *list) { if (list != NULL) { cout << list->data << endl; printListRecursive(list->next); } } #endif