Data Structure: Content
Data Structure: Content
Data Structure: Content
• List
• Abstraction data type List
DATA STRUCTURE • Mathematical model of List
• List operations
(LIST – ARRAY IMPLEMENTATION) • Array-based implementation
• Data structure
Phạm Nguyên Khang
• Implementation of basic list operators
pnkhang@cit.ctu.edu.vn
• Application
Thank you Khánh Vân for the so cute rabbits! Page 3 Page 4
ADT List ADT List
Array Array
elements 0 1 2 3 4 5 6 index
elements 0 1 2 3 4 5 6 index
1 2 3 4 5 6 7 1 2 3 4 5 6 7
last last
Page 15 Page 16
Array-based Implementation Array-based Implementation
Page 17 Page 18
Page 19 Page 20
Array-based Implementation Array-based Implementation
Page 21 Page 22
Page 23 Page 24
Array-based Implementation Array-based Implementation
Page 25 Page 26
Page 27 Page 28
Array-based Implementation Array-based Implementation
//2. Return the address of the element at p // If x is not found return end(L)
return &pL->elements[p - 1];
}
Page 29 Page 30
p=2 last = 4
Page 31 Page 32
Array-based Implementation Array-based Implementation
elements 0 1 2 3 4 5 6 elements 0 1 2 3 4 5 6
1 2 3 4 5 6 7 1 2 3 4 5 6 7
elements 0 1 2 3 4 5 6 elements 0 1 2 3 4 5 6
1 2 3 4 5 6 7 1 2 3 4 5 6 7
elements 0 1 2 3 4 5 6 elements 0 1 2 3 4 5 6
1 2 3 4 5 6 7 1 2 3 4 5 6 7
Page 41 Page 42
elements 0 1 2 3 4 5 6
1 2 3 4 5 6 7
p=2 last = 4
Page 43 Page 44
Array-based Implementation Array-based Implementation
elements 0 1 2 3 4 5 6 elements 0 1 2 3 4 5 6
1 2 3 4 5 6 7 1 2 3 4 5 6 7
elements 0 1 2 3 4 5 6 elements 0 1 2 3 4 5 6
1 2 3 4 5 6 7 1 2 3 4 5 6 7
Page 51 Page 52
Array-based Implementation Array-based Implementation
Page 53 Page 54
Page 55 Page 56
Array-based Implementation Array-based Implementation
store Student Info. 1 Harry Potter 10 • Make an empty list L 1 Harry Potter 10
• name: string (max: 50 characters) 2 Hermione Granger 8 • Insert 5 elements into L in ordered 2 Hermione Granger 8
• mark: integer of its occurrence
– Define a DS List to store
3 Draco Malfoy 7
• Print student List in format
3 Draco Malfoy 7
Page 59 Page 60
THANK YOU