Data Structures in Python: Doubly Linked Lists -- Append and Prepend

preview_player
Показать описание
This video is sponsored by Oxylabs. Oxylabs provides market-leading web scraping solutions for large-scale public data gathering. You can receive data in JSON or CSV format and pay only per successful request. At the moment, Oxylabs offers a free trial.

In this video, we introduce the doubly linked list data structure. We then code up an implementation of this data structure in Python. After that, we look at how to append (add elements to the back of the doubly linked list) and prepend (add elements to the front of the doubly linked list). We then write a print function to verify that the append and prepend functions work as expected. We code the doubly linked list and the corresponding functions up in Python.

The software written in this video is available at:

Do you like the development environment I'm using in this video? It's a customized version of vim that's enhanced for Python development. If you want to see how I set up my vim, I have a series on this here:

Slides can be found here:

If you've found this video helpful and want to stay up-to-date with the latest videos posted on this channel, please subscribe:
Рекомендации по теме
Комментарии
Автор

Happy to report that I completed the prepend function prior to un-pausing the video. This is a huge win for me and couldn't have done it without your singly linked lists and circular linked list videos. It's starting to click!

kimber
Автор

Your playlists about single, double and circular linked lists are great. It really helped me. Thank you for your contribution. Cheers :)

Roshan-xdtl
Автор

Best video on Doubly lists after watching top videos in Youtube. Well explained! Thanks!

enkaibi
Автор

I am trying to write programs before watching your videos and guess what?! I am totally able to! Thanks to your wonderful explanations of Singly Linked Lists, the picture has gotten perfectly clear in my head! God bless you man! <3

Mithileshx
Автор

Really helpful! First time doing doubly linked lists and I was able to follow exactly what you did and why. Thank you!

emerold
Автор

You do a very good job of explaining to someone who has never done programming before (like me) and I thank you for it. Keep up the good work!

OmegaOverlord
Автор

I have watched manny video's on linked list but never understood that concept completely. But after watching this video I understood the concept clearly and now my confidence is also booted and now I am not at all afraid of linked lists. Thank you so much

hackytech
Автор

awesome, waiting for you to add more to this series.. it seriously deserves at least a million views, not even kidding

pythonenthusiast
Автор

Thanks! perfect as usual.
I have a little suggestion, I think that we don't need to assign new_node.next and new_node.prev to None in append() since they both are initialized to None in the Node class.

mulhamjarjanazi
Автор

Honestly, i liked the way you used ppt as well as python editor. Great Explanation Sir. I, m Expecting many examples like circular, Dfs, Bfs, A*, Greedy, Tree Traversing, Graphs. Thank you once again.

prashanthnayak
Автор

you are simply awesome. I was looking for some good video tutorial where i can revise DS using python and seems you are boon. I wonder how i stumble upon your lectures. you deserve more views !

prabhanjantrivedi
Автор

really helpful. the way you explained using diagram, helped me to code myself. Thank you very much.

prakashranjanpatra
Автор

Explained perfectly, 90% of my problems with dLL ceased.

MuhammedAli-ywsd
Автор

Could you make some series about code optimization? I love your videos. Very helpful during studies, a great source of knowledge!

mateuszsmendowski
Автор

Thank you sir, your code is simple and easy to understand and your explanation techniques is also very good. Subscribed the channel!

nishantbanjade
Автор

Thank you for the great video series, I'm really enjoying them as a refresher.
I get that you can just use a variable and update its value on every iteration (like you did for example with append(self, data) or print_list(self) functions, but the problem is that you are creating a new object in memory with every iteration (imagine you have a file with millions of data in that doubly linked list file, so it's not memory efficient). and that's what you did in your class based solution too (you used "cur = self.head" and then you used while loop to update "cur" variable with every iteration (small file is fine, but a big file would require you a lot of extra unnecessary memory).
My solution I came up with today is to use a recursive loop (which doesn't create any extra objects in memory), as it only takes input (update "node = node[1]" and returns value if condition is True).


x = [1, [2, [3, None]]] # This is a simple doubly linked list
def print_list(x):
print(x[0])
if x[1] is None:
pass
else:
return print_list(x[1])
print_list(x)
# 1
# 2
# 3

So basically, you just print the first element (data) and then you return by calling the function again but passing in the new value of "doubly[1]" list to be its 2nd element recursively.
recursive solution is memory saver and efficient and just best practice in this situation in my opinion (memory saver, simple, and just clean).
Your thoughts?

LazerScalper
Автор

OMG, really good video! really good! I just solve my algorithm assignment, thank you!!!!

thrilledjinx
Автор

Amazing video, thank you for the knowledge!!

ouroboros
Автор

You have helped me a lot. Thank you for the tutorial

mohammodroby
Автор

By the way everyone, if you want to have a "smoother" implementation of displaying all the values, you can do something like this:

by declaring this magic method in class Node:
def __repr__(self):
if self.next is None:
return f'{self.data}'
return f'{self.data} -> {self.next}'

and then declaring this magic method in class DoublyLinkedList:
def __repr__(self):
return f'{self.head}'

you can use print(dllist) to display all of the elements in a nice little format.

DogeCharger
welcome to shbcf.ru