Download
linked lists n.
Skip this Video
Loading SlideShow in 5 Seconds..
Linked Lists PowerPoint Presentation
Download Presentation
Linked Lists

Linked Lists

7 Vues Download Presentation
Télécharger la présentation

Linked Lists

- - - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

  1. Linked Lists Mohammed Almashat CS 561 26/03/2006

  2. Outline • Introduction • Insertion Description • Deletion Description • Basic Node Implementation • Conclusion

  3. Outline • Introduction • Insertion Description • Deletion Description • Basic Node Implementation • Conclusion

  4. Introduction • Definitions • Lists and arrays • Nodes and pointers • Single Linked Lists • Double Linked Lists • Circular Lists • Advantages

  5. Introduction • Definitions • Lists and arrays • Nodes and pointers • Single Linked Lists • Double Linked Lists • Circular Lists • Advantages

  6. Lists and arrays • Lists:

  7. Lists and arrays • Arrays: {Size of the following array is = 4}

  8. Introduction • Definitions • Lists and arrays • Nodes and pointers • Single Linked Lists • Double Linked Lists • Circular Lists • Advantages

  9. Nodes and pointers

  10. Introduction • Definitions • Lists and arrays • Nodes and pointers • Single Linked Lists • Double Linked Lists • Circular Lists • Advantages

  11. Single linked lists

  12. Introduction • Definitions • Lists and arrays • Nodes and pointers • Single Linked Lists • Double Linked Lists • Circular Lists • Advantages

  13. Double Linked Lists

  14. Introduction • Definitions • Lists and arrays • Nodes and pointers • Single Linked Lists • Double Linked Lists • Circular Lists • Advantages

  15. Circular Lists

  16. Introduction • Definitions • Lists and arrays • Nodes and pointers • Single Linked Lists • Double Linked Lists • Circular Lists • Advantages

  17. Advantages The Linked List advantages are collected because of the array disadvantages, array disadvantages are: • Array Size • Memory allocation • Insertion and Deletion

  18. Outline • Introduction • Insertion Description • Deletion Description • Basic Node Implementation • Conclusion

  19. Insertion Description • Insertion at the top of the list • Insertion at the end of the list • Insertion in the middle of the list

  20. Insertion Description • Insertion at the top of the list • Insertion at the end of the list • Insertion in the middle of the list

  21. Insertion at the top Steps: • Create a Node • Set the node data Values • Connect the pointers

  22. head 93 // head 48 17 142 Insertion Description • Follow the previous steps and we get Step 1 Step 2 Step 3

  23. Insertion Description • Insertion at the top of the list • Insertion at the end of the list • Insertion in the middle of the list

  24. Insertion at the end Steps: • Create a Node • Set the node data Values • Connect the pointers

  25. // head 48 17 142 Insertion Description • Follow the previous steps and we get Step 1 Step 2 Step 3

  26. Insertion Description • Insertion at the top of the list • Insertion at the end of the list • Insertion in the middle of the list

  27. Insertion in the middle Steps: • Create a Node • Set the node data Values • Break pointer connection • Re-connect the pointers

  28. Insertion Description Step 1 Step 2 Step 3 Step 4

  29. Outline • Introduction • Insertion Description • Deletion Description • Basic Node Implementation • Conclusion

  30. Deletion Description • Deleting from the top of the list • Deleting from the end of the list • Deleting from the middle of the list

  31. Deletion Description • Deleting from the top of the list • Deleting from the end of the list • Deleting from the middle of the list

  32. Deleting from the top Steps • Break the pointer connection • Re-connect the nodes • Delete the node

  33. 6 6 42 42 42 Deletion Description head 4 17 head 4 17 head 4 17

  34. Deletion Description • Deleting from the top of the list • Deleting from the end of the list • Deleting from the middle of the list

  35. Deleting from the end Steps • Break the pointer connection • Set previous node pointer to NULL • Delete the node

  36. 6 6 6 42 42 Deletion Description head 4 17 head 4 17 head 4 17

  37. Deletion Description • Deleting from the top of the list • Deleting from the end of the list • Deleting from the middle of the list

  38. Deleting from the Middle Steps • Set previous Node pointer to next node • Break Node pointer connection • Delete the node

  39. 42 42 42 Deletion Description head 4 17 head 4 17 head 4

  40. Outline • Introduction • Insertion Description • Deletion Description • Basic Node Implementation • Conclusion

  41. Basic Node Implementation The following code is written in C++: Struct Node { int data; //any type of data could be another struct Node *next; //this is an important piece of code “pointer” };

  42. Outline • Introduction • Insertion Description • Deletion Description • Basic Node Implementation • Conclusion