-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlist.cpp
More file actions
32 lines (28 loc) · 771 Bytes
/
list.cpp
File metadata and controls
32 lines (28 loc) · 771 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
//jay ashworth and andy zeng
#include "volsort.h"
//list constructor
List::List() {
head = nullptr;
size = 0;
}
//i wasnt exactly sure about the destructor for the linked list so i used code from stack overflow
//https://stackoverflow.com/questions/2265967/writing-a-linkedlist-destructor
//It essentially iterates through the entire list and deletes each node individually.
List::~List() {
Node* current = head;
while( current != 0 ) {
Node* next = current->next;
delete current;
current = next;
}
head = 0;
}
//adds new element to the front of list
void List::push_front(const std::string &s){
Node* add = head;
head = new Node;
head -> next = add;
head -> string = s;
head -> number = stoi(s);
size++;
}