Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our User Agreement and Privacy Policy.

Slideshare uses cookies to improve functionality and performance, and to provide you with relevant advertising. If you continue browsing the site, you agree to the use of cookies on this website. See our Privacy Policy and User Agreement for details.

Like this presentation? Why not share!

676 views

Published on

Published in:
Technology

No Downloads

Total views

676

On SlideShare

0

From Embeds

0

Number of Embeds

3

Shares

0

Downloads

42

Comments

0

Likes

1

No embeds

No notes for slide

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The third goal prepares a student for the future.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

The second goal is the “nuts and bolts” of the course.

The third goal prepares a student for the future.

- 1. Lecture No.03 Data Structures Dr. Sohail Aslam
- 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; };

No public clipboards found for this slide

×
### Save the most important slides with Clipping

Clipping is a handy way to collect and organize the most important slides from a presentation. You can keep your great finds in clipboards organized around topics.

Be the first to comment