-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.cpp
More file actions
executable file
·92 lines (84 loc) · 1.59 KB
/
LinkedList.cpp
File metadata and controls
executable file
·92 lines (84 loc) · 1.59 KB
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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "LinkedList.h"
#include "Movie.h"
#include "Node.h"
#include <iostream>
#include <string>
#include <fstream>
using namespace std;
LinkedList::LinkedList()
{
head = NULL;
}
void LinkedList::addToStart(Movie data)
{
Node *temp2 = head;
Node *temp = new Node(data);
head = temp;
head -> setNext(temp2);
temp2 = head;
}
void LinkedList::printList()
{
Node *temp = head;
while(temp != NULL)
{
cout << temp->getData()<<"->";
temp = temp->getNext();
}
cout << endl;
}
void LinkedList::addToEnd(Movie data)
{
if (head == NULL)
{
addToStart(data);
}
else
{
Node *temp2 = head;
Node *temp = new Node(data);
while (temp2 -> getNext() != NULL)
{
temp2 = temp2->getNext();
}
temp2 -> setNext(temp);
}
}
void LinkedList::deleteFromStart()
{
head = head->getNext();
}
void LinkedList::deleteFromEnd()
{
Node *temp = head;
while(temp->getNext()->getNext()!=NULL)
{
temp=temp->getNext();
}
temp->setNext(NULL);
}
Movie LinkedList::searchMovie(int rating)
{
Node* temp = head;
while(temp!=NULL)
{
if(temp->getData().getRating() == rating)
return temp->getData();
temp = temp->getNext();
}
}
Node* LinkedList::getHead()
{
return head;
}
int LinkedList::getSize()
{
Node *temp = head;
int size = 0;
while (temp!=NULL)
{
size++;
temp = temp->getNext();
}
return size;
}