-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.cpp
More file actions
62 lines (36 loc) · 977 Bytes
/
LinkedList.cpp
File metadata and controls
62 lines (36 loc) · 977 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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#include "LinkedList.h"
using namespace std;
LinkedList::LinkedList() : head(NULL), tail(NULL), size(0) {}
LinkedList::LinkedList(LinkedList& otherlist) { //copy constructor
for(int i = 0 ; i<getSize(); i++){
insertAtTail(otherlist.getAtIndex(i));
}
}
Card* LinkedList::getHead(){
return &head->getData();
}
Card* LinkedList::getTail(){
return &tail->getData();
}
Card* LinkedList::getAtIndex(int i){
Node* current = head;
for (int j = 0; j <= i; j++){
current = current->getNext();
}
return ¤t.getData();
}
int LinkedList::getSize(){
return size;
}
void LinkedList::insertAtHead(Card* data){
Node* c = new Node(*data);
c->setNext(head);
head = c;
size++;
}
void LinkedList::insertAtTail(Card* data){
tail->setNext(new Node(*data));
tail = tail->getNext();
}
bool LinkedList::insertAtIndex(Card* data, int index){
Node* current = head