Reverse a linked list - Iterative method
HTML-код
- Опубликовано: 27 апр 2013
- See complete series on linked list here:
• Introduction to linked...
See complete series on data structures here:
• Data structures
In this lesson, we have written C program to reverse a singly linked list. This is a very famous interview question. We have solved the problem using iteration.
Feel free to post your questions and suggestions in comments section.
You may like us on facebook:
/ mycodeschool
We are glad that you are finding the current style useful. We will always try to keep the videos simple. So, don't worry about that.
why dont you come back...
and post some recursion related problems?
followed by tries, huffman coding, dp n all
please comeback and teach some dynamic programming and All other algos
Please come back , come back
@@lyfokzz3848 Unfortunately the creator of these videos named Humblefool passed way in a car accident in 2014. So you can't expect more videos from this channel.
@@abhishekguptasarma2060 yup I knew this news...but I'm taking about his partner the one who is explaining in all these videos...
He is doing good...and now working at Google!
Thanks Joey ! I really appreciate your feedback. I Will try to take care of this next time.
DOT is used to access the fields of an object which may be a structure type or a class type. So, if you have a structure like struct {int data; Node* next; }
You can have Node N. and then access fields as N.data = x and N.next = y; But we use dynamic memory for node, because we want to get the memory in run time. So, there is no variable name for the node. we access it through a pointer. So, we go like Node* N = new Node(); Now, fields will be accessed as *(Node).data and *(Node).next
Please come back man!
This is so far the best explanation I've ever seen to reverse a singly linked list, thanks bro!
The Way you proceed breaking the algorithm step by step making mistake and then correcting it in next step is awesome.
I had trouble getting my head around this, now its all clear. Excellent teaching skills indeed!
I would love if there was a video for Directed Graphs And B-Trees
One of the best online tutorials on Data Structures. Thank you so much for making these videos. It's really helpful to all.
Keep up this good work!
I swear you are the best on RUclips. Very clear and concise and with a great amount of depth
I just had to hear the concept from him and could write the algorithm on my own.Please keep up the good work and continue your teaching.
Thanks dude, you are doing a great job for the community. Keep it up.
Absolutely perfect. Simple function to follow. Included implementation and testing. Good stuff!
This problem can't be explained more properly !! Excellent teaching skills !!
this is best tutorial i ever watched compared to all other videos in c and even incomparable to other videos as well.Thanks alot for providing such tutorial. Iam really glad to watch this and never forget this tutorial.
I am following you for the last 6 years. Still, the best with the way you describe. We are very thankfull.
I like the way you visualise the code,great videos!
Hi Thanks for the tutorials, they are awesome !!
Please can you explain the insert () function which accepts head and data as arguments.
at the end you return head , but how is the head manipulated in the "else" of the function ?
thanks
u're doing a great job ...really good keep going...we're with u
Best explanation of reversing a linked list so far.
Watching Lectures from here, reading from Narasimha Karumanchi 's DS and Algo made Easy and attempting same questions from Hackerrank. Enjoying it so far!
Beautiful explanation. I had a hard time figuring out how to reverse the whole link list without creating a new link list with the reverse nodes. Thank you so much. I now can complete my homework.
Excellent teaching , excellent tutorials. One word - DS "simplified".
Perfectly explained! Great video. Thank you!
thanks' my friend. the best lesson of my life :)
thank you very much!! i had hw with linked lists and i had to reverse them but and i knew i
should use a recursive function but i didn't know how to imagine this and then you showed how
Ohk the previous lessons concerning linked list were so great , with a bit of thinking, i reached on the iterative method by myself.
The simplicity and clarity with which the topics are explained , if you are finding it hard to wrap your mind around this problem you should clear your basics , please visit the prev lectures
I really liked this video. Thank you so much!
Really smooth and understandable.You are amazing.Thank you
Thank you and please make videos like this so that everyone can understand these codes very easily.
This is brilliant teaching. I noticed that after reversal the address for next of first node is same as head, i.e., 250 & 250. The head is ok to be 250 and next of first should be 150 which points to second node. That is first after reversal should be 5/150 instead of 5/250 at time 11:26 in video.
invaluable contents sir! really hit the nail right on the head. thanks so much
I bombed this question in my Facebook interview, lol.
for wich position? what are other questions?
@@spartacusche stop
@mycodeschool Thankyou so much for this amazing video.
you lectures are best of all!!!
thanks for these lectures they are really beautifully explained
Really helpful video!! This is incredibly amazing!!! Thanks so much.
I saw another technique in Sumita Arora. It said there, that we can create a newHead node and start inserting elements of the given linked list to the newHead node and return newHead. This reverses the linked list with newHead being the starting node.
@9:42 I believe it should read (*current).next since the parentheses are used because the dereference operator is lower precedence than the . operator.
Bretton Auerbach I am quite sure, you are right. Semantically (current) and current ist the same. The parenthesis are there for precendence adjustion in expressions. Imagine some common arithmetics: 5 + 3 * 5 = 20 but (5 + 3) * 5 = 40. Because multiplication has higher precendence normally. If you read very carefully, you could realize, the order of my example with arithmetic operators is the same as *current.next vs (*current).next
Also, you can read on it in Chapter 6.2 Structures and Functions on page 131 in "The C Programming Language (Second edition based on ANSI C) by Brian W. Kernighan and Dennis M. Ritchie. This book is very well written and will serve you well. Some of the style may be a bit odd and it is best used on a UNIX-like system, but it is very precise.
Instantly liked the video. Finally someone that publishes their video in a proper 21:9 aspect ratio. Perfect for my Ultrawide monitor
This tutorial is very helpful for me, thank you :D
Perfect illustration!
Thank you for this, it is helpful.
Nice, very clear and useful. Thanks!
Really appreciatable for this tutorial
Wow. What a relief this video is after the last fast talking scatterbrains I gave up before here. lol Finally, someone makes some sense. This video is like a breath of fresh air
That was great sir! Except for the thing that for beginners its lil hard to catch your exceptional flow, rest everything is soooooo good sir. Helpful thanks a lot.
Can you please make a video on generalised linked list for multivariable polynomial representation ?
From Only this tutorial I could understand the reverse logic of linked list in iterative manner mind blow explanation. I really liked your teaching efforts.
ruclips.net/video/dR7v1sVX428/видео.html
Thank you for your clear explanation :)
Great explanation. Thanks a lot
This is one of the best explanation on reversing a Linked list ❤️
Great work all points covered
Could you tell us about time and space complexity of these programs... may not be added in the video but in the comments or description section... it wud b great if you could add those...
You are so good at this area. You are like teachers at university. Thank you.
100000 times better than teacher/professor at my university
REALLY CLEARED ALL MY DOUBTS ON LINKED LIST TILL NOW
great video Si..r you always put it in the
best way
Thanks for your comprehensive videos.
May i have access to source code. Is there any place to download source code for this tutorial.
Thanks a lot. Nice tutorial for beginners.
thank u sir....brilliant explanation..
Thank you so much for great knowledge🙏🙏
Pure gold! Thank you.
Thank you so much bro. It helped me a lot
excellent explanation god job !!!!
Thank you so much, I understand and works on my code
Best explanation to reverse a linked list... Thanks so much.
i want to start make tutorials on programming. can you please tell me how you make these videos? what type of board is that you using to explain..a real one or virtual one?
Thank you for the beautiful explanation
amazing explanation! ty! hello from 2020)
Thank you so much Animesh!
THANK YOU SO MUCH SIR.....nice teaching......
you are just awesome! Thanks for the video!
Thank you so much , this video helped me alot
Thanks for the very clear explanation.
comparision between the time complexity in iterative and recuression methods....
Very Good explanation, Thankyou
great explain..thank you
Why don't you come back !!
That the greatest you tube channel of all time for coding.
Thanks, I finally get it.
Sir very good explanation helped a lot for my exam
Thank you so much man ❤🙏🙏
Wonderful explanation
*(current).next same as current->next , i always thought "." is used for variables other than pointers. This means we can always use
*(temp)=head
*(temp).next=*(head)->next
*temp.prev=head->next
Right? I mean these all are correct syntax!
Please Sir....I learn only through repitition and revising some basic concepts as we move towards advanced concepts....Knowledge and patience go hand in hand....please do not change your style of teaching jus because some one cant sit thru repitition
Very well explained!
Your video was so helpful
It also works in Java
Thanks!!!
Hi, i see this implementation is explained in c c++ , not sure but if you are from java background how are you able to connect it or how iy helping you to connect with java
Very nice!. Ek Baar mein samajh aagaya
simple and nice but valuable 13 minutes in my life Thanks
great video, thank you very much
Thank you so much Sir!!!
you are very good
keep going like that !
Thank you this helped me understand better
1st and 3rd are not correct.... When you put '*' operator in front of a variable, you are trying to access the value at the address stored in that variable. So, if temp is pointer to node, you can only access the fields of node as *(temp).data or (*temp).next..... if you say temp = head , you are modifying the address in temp.. Third one is incorrect because you need to use parentheses and say *(temp).prev.... because of operator precedence issue. Second one is correct.
You are great and l need help can you write a program. this program changes that queue order by reversing the order of the odd intergers while leaving the even intergers in place
I am sorry but I beg to differ with you Joey. You may be an expert but novice like me require and love the reiteration of previous material as it solidifies the concept and helps a lot in relating things. For building a strong fundamentals ,it`s really an effective technique....
Best explanation
amazing tutorial
please tell what changes do we have to do in the original insert and print functions
NICE tutorial Thanks
sir please upload a video to copy a stack to another stack withouth using third temporary stack
it's like taking a walk in the past, very nostalgic lecture
The video was good enough (rather, GREAT 👍)
You can improve the explanation by separating the canvas into heap area and stack area, so that the pointer vars are not confused with nodes.
also, you can reuse the head pointer in place of using an extra next pointer.