-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlinkedListType.cpp
More file actions
77 lines (63 loc) · 1.57 KB
/
linkedListType.cpp
File metadata and controls
77 lines (63 loc) · 1.57 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
//COSC 222 - Lab4
//Kurt Fitz - 300213819
//Code use for the linked list
#include <iostream>
#include "linkedListType.h"
using namespace std;
linkedListType::linkedListType() //default constructor
{
first = NULL;
}
void linkedListType::print() const{
string out = "";
digitType* temp;
temp = first;
while(temp->link != NULL){
out = temp->info + out;
temp = temp->link;
}
if(temp->link == NULL)
out = temp->info + out;
cout << out << endl;
}
void linkedListType::insert(const char newItem){
digitType *newNode;
newNode = new digitType();
newNode->info = newItem;
if(first == NULL){
first = newNode;
last = newNode;
} else {
newNode->link = first;
first = newNode;
}
}
digitType* linkedListType::getFirst() const{
return first;
}
void linkedListType::insertFirst(const char& newItem){
digitType *newNode; //pointer to create the new node
newNode = new digitType(); //create the new node
newNode->info = newItem;
newNode->link = first; //insert new node before first
first = newNode;
if(last == NULL) //If list was empty, newNode is also the last node
last = newNode;
}
void linkedListType::insertLast(const char newItem){
digitType *newNode; //pointer to create the new node
newNode = new digitType(); //create the new node
newNode->info = newItem;
newNode->link = NULL;
digitType* current;
current = first;
if(first == NULL){ //If the list is empty, newNode is first
first = newNode;
}
else{
while(current->link != NULL) {
current = current->link;
}
current->link = newNode;
}
}