Lesson 5
Lesson 5
Programming II 1.
2.
Introduction to algorithm
Basic data types and statements
7.
8.
Recursive
File IO
9. Pointers
3. Control structures and Loop
10. Linked Lists
4. Array
11. Stacks and Queues
Linked List data structure 5. Data structure 12. Sorting algorithms
6. Sub-programs 13. Trees
C++
▪ Examples
▪ Element = called a node
▪ In linked list, the first element is head and the last element is tail
Array Vs. Linked List What is Linked list?
❑ Pros and Con ❑ Type of Linked List
▪ Faster access ▪ Elements not in contiguous memory locations myList2 TAIL Last node of the list points to NULL
▪ A single or double linked list can be called a circular linked list when the last ✓Creating a list ✓Display data in list
element (tail) points to the first element (head). ✓Insert a new element to a list ✓Reverse a list
✓ Insert to beginning, end, at a position
✓Combine two lists
✓Delete an element from a list
✓ Delete to beginning, end, at a position
✓… etc.
tmp new(size(Element))
• Create an empty list
tmp→ data 10
head null tmp→ next head
head tmp
while(tmp!=NULL) do
write(tmp→data)
tmp tmp→next
end while
End procedure