cs 225
play

CS 225 Data Structures Se Septembe ber 18 18 Li List - PowerPoint PPT Presentation

CS 225 Data Structures Se Septembe ber 18 18 Li List Implementation G G Carl Evans Li List I Implementation ons 1. 2. Li Linked M Memor ory 2 2 C S 5 List.h 28 class ListNode { 29 T data; 30 ListNode * next;


  1. CS 225 Data Structures Se Septembe ber 18 18 – Li List Implementation G G Carl Evans

  2. Li List I Implementation ons 1. 2.

  3. Li Linked M Memor ory Ø 2 2 C S 5

  4. List.h 28 class ListNode { 29 T data; 30 ListNode * next; 31 ListNode(T & data) : data(data), next(NULL) { } 32 };

  5. List.h List.hpp 1 9 #pragma once #include "List.h" 2 … 3 template <typename T> 14 template <typename T> 4 class List { 15 void List::insertAtFront(const T& d) { 5 public: 16 … /* ... */ 17 19 18 20 private: 19 21 class ListNode { 20 22 public: 21 23 T data; 22 } 24 ListNode * next; 25 ListNode(T & data) : data(data), next(NULL) { } 26 }; 27 28 ListNode *head_; … };

  6. Li Linked M Memor ory Ø 2 2 C S 5 head_

  7. List.hpp 57 template <typename T> 58 typename List<T>::ListNode *& List<T>::_index(unsigned index) { 59 60 61 } 62 63 64 65

  8. Li Linked M Memor ory Ø 2 2 C S 5 head_

  9. List.hpp // Iterative Solution: template <typename T> typename List<T>::ListNode *& List<T>::_index(unsigned index) { if (index == 0) { return head; } else { ListNode *thru = head; for (unsigned i = 0; i < index - 1; i++) { thru = thru->next; } return thru->next; } }

  10. Li Linked M Memor ory Ø 2 2 C S 5 head_

  11. List.cpp 48 template <typename T> 49 T & List<T>::operator[](unsigned index) { 50 51 52 53 54 55 56 57 58 }

  12. Li Linked M Memor ory Ø 2 2 C S 5 head_

  13. List.cpp 90 template <typename T> 91 void List<T>::insert(const T & t, unsigned index) { 92 93 94 95 96 97 98 99 }

  14. Li Linked M Memor ory Ø 2 2 C S 5 head_

  15. List.cpp 103 template <typename T> 104 T List<T>::remove(unsigned index) { 105 106 107 108 109 110 111 112 }

  16. Li Linked M Memor ory Ø 2 2 C S 5 head_

  17. Se Sentinel N Nod ode Ø 2 2 C S 5 head_

  18. Li List I Implementation ons 1. Linked List 2.

  19. List.h 1 #pragma once 2 3 template <typename T> 4 class List { 5 public: … /* ... */ 28 private: 29 30 31 32 33 34 35 36 37 38 39 40 41 42 };

  20. Arr Array I Implementation C S 2 5 2 [0] [1] [2] [3] [4]

  21. Arr Array I Implementation insertAtFront: C S 2 2 5 [0] [1] [2] [3] [4]

  22. Re Resize Stra rategy – De Details ails

  23. Re Resize Stra rategy – De Details ails

  24. Arr Array I Implementation C S 2 2 5 T* arr_: [0] [1] [2] [3] [4] T* zero_

  25. Arr Array I Implementation C S 2 2 5 T* arr_: [0] [1] [2] [3] [4] T* zero_

  26. Array I Arr Implementation C S 2 2 5 W T* arr: [0] [1] [2] [3] [4] [5] T* zero

  27. Array I Arr Implementation C S 2 2 5 W T* arr: [0] [1] [2] [3] [4] [5] T* zero

  28. Arr Array I Implementation Singly Linked List Array Insert/Remove at front Insert at given element Remove at given element Insert at arbitrary location Remove at arbitrary location

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend