Docsity

Cpp Code for Linked List - Data Stuctures - Lecture Slides, Slides of Data Structures and Algorithms

Partial preview of the text

Download Cpp Code for Linked List - Data Stuctures - Lecture Slides and more Slides Data Structures and Algorithms in PDF only on Docsity!

AL 1

Linked List

ļ‚§ Actual picture in memory:

1051 1052 1055 1059 1060 1061 1062 1063 1064 1056 1057 1058 1053 1054 2 6 8 7 1 1051 1063 1057 1060 0 head 1054 current 1063 2 6 8 7 1 head current 1065

AL 2

Linked List Operations

ļ‚§ add(9): Create a new node in memory to hold ā€˜9’

Node* newNode = new Node(9); newNod 9 e

AL 4

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; };

AL 5

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; };

AL 7

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; };

AL 8

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; };

AL 10

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; };

AL 11

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; };

AL 13

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; };

AL 14

#include <stdlib.h>

#include "Node.cpp"

class List {

public:

// Constructor

List() {

headNode = new Node();

headNode->setNext(NULL);

currentNode = NULL;

size = 0;

AL 16

#include <stdlib.h>

#include "Node.cpp"

class List {

public:

// Constructor

List() {

headNode = new Node();

headNode->setNext(NULL);

currentNode = NULL;

size = 0;

AL 17

#include <stdlib.h>

#include "Node.cpp"

class List {

public:

// Constructor

List() {

headNode = new Node();

headNode->setNext(NULL);

currentNode = NULL;

size = 0;

AL 19

#include <stdlib.h>

#include "Node.cpp"

class List {

public:

// Constructor

List() {

headNode = new Node();

headNode->setNext(NULL);

currentNode = NULL;

size = 0;

AL 20

#include <stdlib.h>

#include "Node.cpp"

class List {

public:

// Constructor

List() {

headNode = new Node();

headNode->setNext(NULL);

currentNode = NULL;

size = 0;