SlideShare a Scribd company logo
Lecture No.03
Data Structures
Dr. Sohail Aslam
Linked List


Actual picture in memory:
1051
1052
1053

1063
2

1055

head

1063

1054

current

6

1051

1056

2

6

8

7

1

1057
1058

current

7
1060

1059
1060
1061
head

1
0

1062

1054

1063

8

1064

1057

1065
Linked List Operations


add(9): Create a new node in memory to hold ‘9’
Node* newNode = new Node(9);

newNode

9
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
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
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;
};
C++ Code for Linked List
void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List


void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List


void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List


void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List


void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
C++ Code for Linked List



void add(int addObject) {
Node* newNode = new Node();
newNode->set(addObject);
if( currentNode != NULL ){
newNode->setNext(currentNode->getNext());
currentNode->setNext( newNode );
lastCurrentNode = currentNode;
currentNode = newNode;
}
else {
newNode->setNext(NULL);
headNode->setNext(newNode);
lastCurrentNode = headNode;
currentNode = newNode;
}
size++;
};
Building a Linked List
List list;

headNode

size=0
Building a Linked List
List list;

headNode

size=0
currentNode

list.add(2);

headNode
lastcurrentNode

2

size=1
Building a Linked List
List list;

headNode

size=0
currentNode

list.add(2);

headNode

2

size=1

lastcurrentNode

currentNode

list.add(6);

headNode

2

6

lastcurrentNode

size=2
Building a Linked List
List.add(8); list.add(7); list.add(1);

currentNode
headNode

2

6

8

7

lastcurrentNode

1

size=5
C++ Code for Linked List
int get() {
if (currentNode != NULL)
return currentNode->get();
};
C++ Code for Linked List
bool next() {
if (currentNode == NULL) return false;
lastCurrentNode = currentNode;
currentNode = currentNode->getNext();
if (currentNode == NULL || size == 0)
return false;
else
return true;
};

More Related Content

PPT
computer notes - Data Structures - 3
PDF
Rainer Grimm, “Functional Programming in C++11”
DOCX
Dotnet 18
PPT
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
PPT
Networking Core Concept
PDF
Bartosz Milewski, “Re-discovering Monads in C++”
PDF
C programs
PDF
Core java pract_sem iii
computer notes - Data Structures - 3
Rainer Grimm, “Functional Programming in C++11”
Dotnet 18
DATASTRUCTURES PPTS PREPARED BY M V BRAHMANANDA REDDY
Networking Core Concept
Bartosz Milewski, “Re-discovering Monads in C++”
C programs
Core java pract_sem iii

What's hot (20)

PDF
Дмитрий Верескун «Синтаксический сахар C#»
PPT
Whats new in_csharp4
PDF
DCN Practical
DOCX
Java programs
PPT
Collection Core Concept
PPTX
CppConcurrencyInAction - Chapter07
DOCX
PDF
DSU C&C++ Practical File Diploma
PDF
Java Practical File Diploma
PDF
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
PDF
C Prog - Array
PDF
C program
PDF
Python Performance 101
PDF
DOCX
XTW_Import
PPT
Cquestions
PDF
Typelevel summit
PDF
Herding types with Scala macros
ZIP
とある断片の超動的言語
PPTX
Class list data structure
Дмитрий Верескун «Синтаксический сахар C#»
Whats new in_csharp4
DCN Practical
Java programs
Collection Core Concept
CppConcurrencyInAction - Chapter07
DSU C&C++ Practical File Diploma
Java Practical File Diploma
2 BytesC++ course_2014_c3_ function basics&parameters and overloading
C Prog - Array
C program
Python Performance 101
XTW_Import
Cquestions
Typelevel summit
Herding types with Scala macros
とある断片の超動的言語
Class list data structure
Ad

Similar to Data structures cs301 power point slides lecture 03 (20)

PPT
Lecture 3 List of Data Structures & Algorithms
PPT
linked-list - Abstract data type (ADT) Linked Lists
PPT
Abstract data types
PPT
Algo>ADT list & linked list
PDF
C++ CodeConsider the LinkedList class and the Node class that we s.pdf
PPT
List
PPT
Chapter 5 ds
PDF
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
PPTX
DSA(1).pptx
PPT
linkedlistwith animations.ppt
PPT
Array linked list.ppt
PPT
linked-list.ppt
PPTX
Linked lists a
PDF
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
PDF
computer notes - Linked list inside computer memory
PDF
This assignment and the next (#5) involve design and development of a.pdf
PPTX
Lecture 4 data structures and algorithms
PPTX
Linked List.pptx
PPTX
3.linked list
DOCX
C++ Please write the whole code that is needed for this assignment- wr.docx
Lecture 3 List of Data Structures & Algorithms
linked-list - Abstract data type (ADT) Linked Lists
Abstract data types
Algo>ADT list & linked list
C++ CodeConsider the LinkedList class and the Node class that we s.pdf
List
Chapter 5 ds
Create a link list. Add some nodes to it, search and delete nodes fro.pdf
DSA(1).pptx
linkedlistwith animations.ppt
Array linked list.ppt
linked-list.ppt
Linked lists a
implement the ListLinked ADT (the declaration is given in ListLinked.pdf
computer notes - Linked list inside computer memory
This assignment and the next (#5) involve design and development of a.pdf
Lecture 4 data structures and algorithms
Linked List.pptx
3.linked list
C++ Please write the whole code that is needed for this assignment- wr.docx
Ad

Recently uploaded (20)

PDF
Mobile App Security Testing_ A Comprehensive Guide.pdf
PDF
gpt5_lecture_notes_comprehensive_20250812015547.pdf
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
MYSQL Presentation for SQL database connectivity
PDF
Advanced methodologies resolving dimensionality complications for autism neur...
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PPTX
Spectroscopy.pptx food analysis technology
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
MIND Revenue Release Quarter 2 2025 Press Release
PPTX
Big Data Technologies - Introduction.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPT
“AI and Expert System Decision Support & Business Intelligence Systems”
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
PDF
Approach and Philosophy of On baking technology
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Mobile App Security Testing_ A Comprehensive Guide.pdf
gpt5_lecture_notes_comprehensive_20250812015547.pdf
Reach Out and Touch Someone: Haptics and Empathic Computing
MYSQL Presentation for SQL database connectivity
Advanced methodologies resolving dimensionality complications for autism neur...
Programs and apps: productivity, graphics, security and other tools
20250228 LYD VKU AI Blended-Learning.pptx
Spectroscopy.pptx food analysis technology
Spectral efficient network and resource selection model in 5G networks
MIND Revenue Release Quarter 2 2025 Press Release
Big Data Technologies - Introduction.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
“AI and Expert System Decision Support & Business Intelligence Systems”
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation
The Rise and Fall of 3GPP – Time for a Sabbatical?
Profit Center Accounting in SAP S/4HANA, S4F28 Col11
Approach and Philosophy of On baking technology
Dropbox Q2 2025 Financial Results & Investor Presentation
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Data structures cs301 power point slides lecture 03

  • 2. Linked List  Actual picture in memory: 1051 1052 1053 1063 2 1055 head 1063 1054 current 6 1051 1056 2 6 8 7 1 1057 1058 current 7 1060 1059 1060 1061 head 1 0 1062 1054 1063 8 1064 1057 1065
  • 3. Linked List Operations  add(9): Create a new node in memory to hold ‘9’ Node* newNode = new Node(9); newNode 9
  • 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; };
  • 25. C++ Code for Linked List void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 26. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 27. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 28. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 29. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 30. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 31. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 32. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 33. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 34. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 35. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 36. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 37. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 38. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 39. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 40. C++ Code for Linked List  void add(int addObject) { Node* newNode = new Node(); newNode->set(addObject); if( currentNode != NULL ){ newNode->setNext(currentNode->getNext()); currentNode->setNext( newNode ); lastCurrentNode = currentNode; currentNode = newNode; } else { newNode->setNext(NULL); headNode->setNext(newNode); lastCurrentNode = headNode; currentNode = newNode; } size++; };
  • 41. Building a Linked List List list; headNode size=0
  • 42. Building a Linked List List list; headNode size=0 currentNode list.add(2); headNode lastcurrentNode 2 size=1
  • 43. Building a Linked List List list; headNode size=0 currentNode list.add(2); headNode 2 size=1 lastcurrentNode currentNode list.add(6); headNode 2 6 lastcurrentNode size=2
  • 44. Building a Linked List List.add(8); list.add(7); list.add(1); currentNode headNode 2 6 8 7 lastcurrentNode 1 size=5
  • 45. C++ Code for Linked List int get() { if (currentNode != NULL) return currentNode->get(); };
  • 46. C++ Code for Linked List bool next() { if (currentNode == NULL) return false; lastCurrentNode = currentNode; currentNode = currentNode->getNext(); if (currentNode == NULL || size == 0) return false; else return true; };

Editor's Notes

  • #3: End of lecture 2 The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #4: The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #5: The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #6: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #7: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #8: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #9: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #10: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #11: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #12: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #13: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #14: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #15: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #16: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #17: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #18: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #19: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #20: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #21: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #22: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #23: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #24: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #25: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #26: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #27: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #28: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #29: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #30: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #31: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #32: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #33: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #34: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #35: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #36: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #37: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #38: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #39: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #40: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #41: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #42: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #43: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #44: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #45: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #46: The first goal is a worldview to adopt The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • #47: End of lecture 3 The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.