4. Linked List Operations
add(9): Create a new node in memory to hold ‘9’
Node* newNode = new Node(9);
newNode
Link the new node into the list
head
2
6
8
current
7
2
3
9
newNode
1
1
size=5 6
9
5. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
6. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
7. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
8. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
9. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
10. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
11. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
12. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
13. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
14. C++ Code for Linked List
The Node class
class Node {
public:
int get() { return object; };
void set(int object) { this->object = object; };
Node *getNext() { return nextNode; };
void setNext(Node *nextNode)
{ this->nextNode = nextNode; };
private:
int object;
Node *nextNode;
};
15. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
16. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
17. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
18. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
19. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
20. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
21. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
22. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
23. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};
24. C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
public:
// Constructor
List() {
headNode = new Node();
headNode->setNext(NULL);
currentNode = NULL;
size = 0;
};