Hood College STL Style List Container Project
I’m studying and need help with a Computer Science question to help me learn.
#include <iostream>
using namespace std; struct node { int data; node *prev; node *next; }; class lista { public: lista() {head = new node; head->next = head; head->prev = head;} void push_front(const int &val) { node * np; np = new node; np->data = val; np -> next = head -> next; head -> next -> prev = np; np -> prev = head; head -> next = np; } void push_back(const int &val); void pop_front(); void pop_back(); const int& front() const; const int& back() const; friend void display_list(const lista &obj); int size() const; bool empty() const; void clear(); private: node * head; }; void display_list(const lista &obj) { node* np; np = obj.head->next; while (np != obj.head) { cout << np->data << endl; np = np->next; } } int main() { lista mylist; display_list(mylist); mylist.push_front(5); display_list(mylist); }