How To Win Coding Competitions: Secrets of Champions: Pavel Krotkov Saint Petersburg 2016
How To Win Coding Competitions: Secrets of Champions: Pavel Krotkov Saint Petersburg 2016
Pavel Krotkov
Saint Petersburg 2016
Operations on list
2/9
Operations on list
2/9
Operations on list
2/9
Operations on list
2/9
Operations on list
2/9
Main idea
3/9
Main idea
3/9
Main idea
3/9
Main idea
3/9
Main idea
3/9
Main idea
3/9
Main idea
head 3 6 2 null
3/9
Insertions
4/9
Insertions
4/9
Insertions
head 3 6 2 null
4/9
Insertions
head 3 6 2 null
Note
I we need to have a link to an element after which we want to insert a new one
4/9
Deletions
We also can delete any element from any place in this structure.
5/9
Deletions
We also can delete any element from any place in this structure.
I deletion takes only changing one link
5/9
Deletions
We also can delete any element from any place in this structure.
I deletion takes only changing one link
head 3 6 2 null
5/9
Deletions
We also can delete any element from any place in this structure.
I deletion takes only changing one link
head 3 6 2 null
Note
I we need to have a link to an element previous to an element we want to delete
5/9
Code examples
6/9
Code examples
6/9
Code examples
insert(p, new)
new.next ← p.next
p.next ← new
7/9
Code examples
insert(p, new)
new.next ← p.next
p.next ← new
delete next(p)
p.next ← p.next.next
7/9
Final thoughts
You should be very careful with potential null references while implementing this data
structure.
8/9
Final thoughts
You should be very careful with potential null references while implementing this data
structure.
8/9
Thank you
for your attention!
9/9