-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLinkedList.cpp
More file actions
43 lines (39 loc) · 744 Bytes
/
LinkedList.cpp
File metadata and controls
43 lines (39 loc) · 744 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
//
// Created by Ricky Marly on 9/17/20.
//
#include "LinkedList.h"
#include <iostream>
using namespace std;
LinkedList::LinkedList()
{
head = 0;
}
void LinkedList::append(int value_in)
{
if (head == 0)
{
head = new Node();
head->setValue(value_in);
head->setNext(0);
}
else
{
Node* myPtr = head;
while (myPtr->getNext() != 0)
{
myPtr = myPtr->getNext();
}
myPtr->setNext(new Node());
myPtr->getNext()->setValue(value_in);
myPtr->getNext()->setNext(0);
}
}
void LinkedList::print()
{
Node* myPtr = head;
while (myPtr != 0)
{
cout << myPtr->getValue() << " ";
myPtr = myPtr->getNext();
}
}