Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "linkedlist.h"
- LL::LL() { }
- bool LL::empty() {
- return head == NULL;
- }
- size_t LL::size() {
- int total = 0;
- node *curr = head;
- while (curr != NULL) {
- total++;
- curr = curr->next;
- }
- return total;
- }
- void LL::clear() {
- node *curr = head;
- node *todelete = curr;
- while (curr != NULL) {
- curr = curr->next;
- delete todelete;
- todelete = curr;
- }
- head = NULL;
- }
- void LL::pop_front() {
- if (head != NULL) {
- node *newhead = head->next;
- delete head;
- head = newhead;
- }
- }
- void LL::push_front(const int &x) {
- node *newhead = new node;
- newhead->data = x;
- newhead->next = head;
- head = newhead;
- }
- int& LL::front() {
- return head->data;
- }
- const int& LL::front() const {
- return head->data;LINKEDLIST_H
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement