linked list

46
Lecture No.03 Data Structures Dr. Sohail Aslam

Upload: ism33

Post on 17-Sep-2015

8 views

Category:

Documents


2 download

DESCRIPTION

Implementing linked list

TRANSCRIPT

Data StructuresEnd of lecture 2
The second goal is the “nuts and bolts” of the course.
The third goal prepares a student for the future.
Linked List Operations
add(9): Create a new node in memory to hold ‘9’
Node* newNode = new Node(9);
9
newNode
The second goal is the “nuts and bolts” of the course.
The third goal prepares a student for the future.
Linked List Operations
add(9): Create a new node in memory to hold ‘9’
Node* newNode = new Node(9);
9
newNode
2
head
1
3
2
6
8
7
1
current
9
newNode
The second goal is the “nuts and bolts” of the course.
The third goal prepares a student for the future.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
The Node class
Node *getNext() { return nextNode; };
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
#include <stdlib.h>
#include "Node.cpp"
class List {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
C++ Code for Linked List
void add(int addObject) {
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.
Building a Linked List
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.
Building a Linked List
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.
Building a Linked List
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.
Building a Linked List
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.
C++ Code for Linked List
int get() {
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.
C++ Code for Linked List
bool next() {
lastCurrentNode = currentNode;
return false;
End of lecture 3
The second goal is the “nuts and bolts” of the course.
The third goal prepares a student for the future.