Your SlideShare is downloading. ×
0
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Computer notes  - Linked List
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

×
Saving this for later? Get the SlideShare app to save on your phone or tablet. Read anywhere, anytime – even offline.
Text the download link to your phone
Standard text messaging rates apply

Computer notes - Linked List

1,701

Published on

Create a new node in memory to hold ‘9’. Link the new node into the list. C++ Code for Linked List

Create a new node in memory to hold ‘9’. Link the new node into the list. C++ Code for Linked List

Published in: Education, Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,701
On Slideshare
0
From Embeds
0
Number of Embeds
1
Actions
Shares
0
Downloads
122
Comments
0
Likes
2
Embeds 0
No embeds

Report content
Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
No notes for slide
  • End of lecture 2 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 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • 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.
  • End of lecture 3 The second goal is the “nuts and bolts” of the course. The third goal prepares a student for the future.
  • Transcript

    • 1. Class No.03 Data Structures http://ecomputernotes.com
    • 2. Linked List <ul><li>Actual picture in memory: </li></ul>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 1063 current 6 8 7 1 head current 1065 http://ecomputernotes.com 2
    • 3. Linked List Operations <ul><li>add(9): Create a new node in memory to hold ‘9’ Node* newNode = new Node(9); </li></ul>http://ecomputernotes.com 9 newNode
    • 4. Linked List Operations <ul><li>add(9): Create a new node in memory to hold ‘9’ Node* newNode = new Node(9); </li></ul><ul><li>Link the new node into the list </li></ul>http://ecomputernotes.com 9 newNode 2 6 8 7 1 head current size=5 6 9 newNode 1 3 2
    • 5. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com
    • 6. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 7. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 8. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 9. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 10. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 11. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 12. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 13. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 14. C++ Code for Linked List <ul><li>The Node class </li></ul><ul><li>class Node { </li></ul><ul><li>public: </li></ul><ul><li>int get() { return object; }; </li></ul><ul><li>void set(int object) { this->object = object; }; </li></ul><ul><li>Node *getNext() { return nextNode; }; </li></ul><ul><li>void setNext(Node *nextNode) </li></ul><ul><li>{ this->nextNode = nextNode; }; </li></ul><ul><li>private: </li></ul><ul><li>int object; </li></ul><ul><li>Node *nextNode; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 15. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com
    • 16. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 17. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 18. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 19. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 20. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 21. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 22. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 23. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 24. <ul><li>#include <stdlib.h> </li></ul><ul><li>#include &quot;Node.cpp&quot; </li></ul><ul><li>class List { </li></ul><ul><li>public: </li></ul><ul><li>// Constructor </li></ul><ul><li>List() { </li></ul><ul><li>headNode = new Node(); </li></ul><ul><li>headNode->setNext(NULL); </li></ul><ul><li>currentNode = NULL; </li></ul><ul><li>size = 0; </li></ul><ul><li>}; </li></ul>C++ Code for Linked List http://ecomputernotes.com 
    • 25. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com
    • 26. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 27. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 28. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 29. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 30. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 31. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 32. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 33. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 34. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 35. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 36. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 37. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 38. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 39. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 40. C++ Code for Linked List <ul><li>void add(int addObject) { </li></ul><ul><li>Node* newNode = new Node(); </li></ul><ul><li>newNode->set(addObject); </li></ul><ul><li>if( currentNode != NULL ){ </li></ul><ul><li> newNode->setNext(currentNode->getNext()); </li></ul><ul><li> currentNode->setNext( newNode ); </li></ul><ul><li> lastCurrentNode = currentNode; </li></ul><ul><li> currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>else { </li></ul><ul><li> newNode->setNext(NULL); </li></ul><ul><li> headNode->setNext(newNode); </li></ul><ul><li> lastCurrentNode = headNode; </li></ul><ul><li>currentNode = newNode; </li></ul><ul><li>} </li></ul><ul><li>size++; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com 
    • 41. Building a Linked List headNode size=0 List list; http://ecomputernotes.com
    • 42. Building a Linked List headNode 2 headNode currentNode size=1 lastcurrentNode size=0 List list; list.add(2); http://ecomputernotes.com
    • 43. Building a Linked List headNode 2 headNode currentNode size=1 lastcurrentNode 2 6 headNode currentNode size=2 lastcurrentNode size=0 List list; list.add(2); list.add(6); http://ecomputernotes.com
    • 44. Building a Linked List <ul><li>List.add(8); list.add(7); list.add(1); </li></ul>2 6 1 headNode currentNode size=5 lastcurrentNode 8 http://ecomputernotes.com 7
    • 45. C++ Code for Linked List <ul><li>int get() { </li></ul><ul><li>if (currentNode != NULL) </li></ul><ul><li> return currentNode->get(); </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com
    • 46. C++ Code for Linked List <ul><li>bool next() { </li></ul><ul><li>if (currentNode == NULL) return false; </li></ul><ul><li>lastCurrentNode = currentNode; </li></ul><ul><li>currentNode = currentNode->getNext(); </li></ul><ul><li>if (currentNode == NULL || size == 0) </li></ul><ul><li>return false; </li></ul><ul><li>else </li></ul><ul><li>return true; </li></ul><ul><li>}; </li></ul>http://ecomputernotes.com

    ×