#include class ListElem { public: int value; // Integer ListElem *next; // Pointer used to make link }; class List { public: ListElem *head; void InsertAtHead(ListElem * elem) { elem->next = this->head; this->head = elem; } void DeleteAtHead() { ListElem *p2; if (this->head == NULL ) return; p2 = this->head; this->head = p2->next; delete p2; } }; void Print(ListElem *head) { ListElem *p; p = head; // Very important: start at first element cout << "List ==> "; while ( p != NULL ) { cout << p->value << " "; // Access value stored in list element p = p->next; // Visit next element in list } cout << "\n\n"; } int main(int argc, char *argv[]) { List myList; ListElem *p; p = new ListElem; p->value = 1500; myList.InsertAtHead(p); Print(myList.head); p = new ListElem; p->value = 2500; myList.InsertAtHead(p); Print(myList.head); p = new ListElem; p->value = 3500; myList.InsertAtHead(p); Print(myList.head); myList.DeleteAtHead(); Print(myList.head); }