#pragma once #include using namespace std; class linkedList { private: class node { public: double data; node* next; node(double x) { data = x; next = nullptr; } }; node* head; //print the list starting at p in backwards order. void printBackwards(node* p) { if (p == nullptr) //base case { } else //recursive { printBackwards(p->next); cout << p->data << endl; } } //print the list starting at p in forwards order. void printForwardsRec(node* p) { if (p == nullptr) //base case { } else //recursive { cout << p->data << endl; printForwardsRec(p->next); } } public: linkedList() { head = nullptr; } void addFront(double x) { node* baby = new node(x); baby->next = head; head = baby; } void printBackwards() { printBackwards(head); } //O(n) void printForwards() { printForwardsRec(head); //for (node* i = head; i != nullptr; i = i->next) // cout << i->data << endl; } };