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

Комментарии • 316

  • @mycodeschool
    @mycodeschool  11 лет назад +208

    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.

    • @lyfokzz3848
      @lyfokzz3848 4 года назад +11

      why dont you come back...
      and post some recursion related problems?
      followed by tries, huffman coding, dp n all

    • @likithmanoj3891
      @likithmanoj3891 4 года назад +7

      please comeback and teach some dynamic programming and All other algos

    • @RanjanKumar-bu7ws
      @RanjanKumar-bu7ws 4 года назад +3

      Please come back , come back

    • @abhishekguptasarma2060
      @abhishekguptasarma2060 3 года назад +3

      ​@@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.

    • @lyfokzz3848
      @lyfokzz3848 3 года назад +8

      @@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!

  • @mycodeschool
    @mycodeschool  11 лет назад +4

    Thanks Joey ! I really appreciate your feedback. I Will try to take care of this next time.

  • @mycodeschool
    @mycodeschool  11 лет назад +43

    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

    • @yogipro183
      @yogipro183 2 года назад +3

      Please come back man!

  • @stevenlin2634
    @stevenlin2634 4 года назад +15

    This is so far the best explanation I've ever seen to reverse a singly linked list, thanks bro!

  • @sauravbhagat4737
    @sauravbhagat4737 6 лет назад +17

    The Way you proceed breaking the algorithm step by step making mistake and then correcting it in next step is awesome.

  • @1317jack
    @1317jack 9 лет назад +50

    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

  • @armaan8449
    @armaan8449 8 лет назад +138

    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!

  • @quanny4690
    @quanny4690 5 лет назад +1

    I swear you are the best on RUclips. Very clear and concise and with a great amount of depth

  • @varunn3286
    @varunn3286 5 лет назад +3

    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.

  • @afnanreh6811
    @afnanreh6811 9 лет назад +5

    Thanks dude, you are doing a great job for the community. Keep it up.

  • @chan4est
    @chan4est 8 лет назад +4

    Absolutely perfect. Simple function to follow. Included implementation and testing. Good stuff!

  • @RaviRanjan_ssj4
    @RaviRanjan_ssj4 9 лет назад +14

    This problem can't be explained more properly !! Excellent teaching skills !!

  • @tharunkumar7285
    @tharunkumar7285 6 лет назад

    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.

  • @enamulhaqueshamim4439
    @enamulhaqueshamim4439 2 года назад

    I am following you for the last 6 years. Still, the best with the way you describe. We are very thankfull.

  • @chilinouillesdepommesdeter819
    @chilinouillesdepommesdeter819 6 лет назад

    I like the way you visualise the code,great videos!

  • @ironhidesatz
    @ironhidesatz 9 лет назад +4

    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

  • @harshalbhite6795
    @harshalbhite6795 7 лет назад +2

    u're doing a great job ...really good keep going...we're with u

  • @sonusingh-zr6xw
    @sonusingh-zr6xw 3 года назад +1

    Best explanation of reversing a linked list so far.

  • @joeljohnson1338
    @joeljohnson1338 4 года назад +1

    Watching Lectures from here, reading from Narasimha Karumanchi 's DS and Algo made Easy and attempting same questions from Hackerrank. Enjoying it so far!

  • @alxprogrmz6093
    @alxprogrmz6093 6 лет назад +15

    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.

  • @mahdivs
    @mahdivs 6 лет назад

    Excellent teaching , excellent tutorials. One word - DS "simplified".

  • @ankitrajput85
    @ankitrajput85 6 лет назад

    Perfectly explained! Great video. Thank you!

  • @surfmoment
    @surfmoment 7 лет назад +7

    thanks' my friend. the best lesson of my life :)

  • @yannai1705
    @yannai1705 7 лет назад +1

    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

  • @bladerunner2912
    @bladerunner2912 4 года назад

    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

  • @ankitaa.baruah3970
    @ankitaa.baruah3970 9 лет назад +1

    I really liked this video. Thank you so much!

  • @togrulnbili8703
    @togrulnbili8703 6 лет назад

    Really smooth and understandable.You are amazing.Thank you

  • @ardhendushekhar8417
    @ardhendushekhar8417 4 года назад +1

    Thank you and please make videos like this so that everyone can understand these codes very easily.

  • @himanshunayak3825
    @himanshunayak3825 2 года назад +1

    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.

  • @Young10489
    @Young10489 3 года назад

    invaluable contents sir! really hit the nail right on the head. thanks so much

  • @Xinthose
    @Xinthose 4 года назад +37

    I bombed this question in my Facebook interview, lol.

  • @suryaprakashn5994
    @suryaprakashn5994 3 года назад

    @mycodeschool Thankyou so much for this amazing video.

  • @venkatesh3439
    @venkatesh3439 4 года назад

    you lectures are best of all!!!

  • @nishantsahu8381
    @nishantsahu8381 4 года назад +1

    thanks for these lectures they are really beautifully explained

  • @tobytran2775
    @tobytran2775 6 лет назад

    Really helpful video!! This is incredibly amazing!!! Thanks so much.

  • @GameSteals
    @GameSteals 7 лет назад

    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.

  • @BrettonAuerbach
    @BrettonAuerbach 9 лет назад +10

    @9:42 I believe it should read (*current).next since the parentheses are used because the dereference operator is lower precedence than the . operator.

    • @KaliszAd
      @KaliszAd 9 лет назад +2

      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.

  • @aRoamingDuck
    @aRoamingDuck 7 лет назад +16

    Instantly liked the video. Finally someone that publishes their video in a proper 21:9 aspect ratio. Perfect for my Ultrawide monitor

  • @joycewang5019
    @joycewang5019 5 лет назад

    This tutorial is very helpful for me, thank you :D

  • @Akanksha8618
    @Akanksha8618 8 лет назад

    Perfect illustration!

  • @FatherTime89
    @FatherTime89 8 лет назад

    Thank you for this, it is helpful.

  • @mkmk418
    @mkmk418 9 лет назад

    Nice, very clear and useful. Thanks!

  • @kishoreprabhu3523
    @kishoreprabhu3523 5 лет назад

    Really appreciatable for this tutorial

  • @sethother8012
    @sethother8012 2 года назад

    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

  • @mannambhavani4266
    @mannambhavani4266 3 года назад

    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.

  • @zainabmerchant4378
    @zainabmerchant4378 5 лет назад +1

    Can you please make a video on generalised linked list for multivariable polynomial representation ?

  • @LetsPlayClipAll
    @LetsPlayClipAll 4 года назад

    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.

    • @jaffarjawed4407
      @jaffarjawed4407 4 года назад

      ruclips.net/video/dR7v1sVX428/видео.html

  • @yeerinadebnath5057
    @yeerinadebnath5057 9 лет назад

    Thank you for your clear explanation :)

  • @rockingdude8383
    @rockingdude8383 8 лет назад

    Great explanation. Thanks a lot

  • @meghapaul1496
    @meghapaul1496 3 года назад

    This is one of the best explanation on reversing a Linked list ❤️

  • @mohitshrivastava1158
    @mohitshrivastava1158 7 лет назад

    Great work all points covered

  • @KishoreKumar-sl6fk
    @KishoreKumar-sl6fk 5 лет назад

    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...

  • @merveisk1423
    @merveisk1423 5 лет назад +1

    You are so good at this area. You are like teachers at university. Thank you.

    • @hrithiksingh73
      @hrithiksingh73 3 года назад

      100000 times better than teacher/professor at my university

  • @ankitbhardwaj9566
    @ankitbhardwaj9566 5 лет назад

    REALLY CLEARED ALL MY DOUBTS ON LINKED LIST TILL NOW

  • @mohitahlawat4944
    @mohitahlawat4944 4 года назад

    great video Si..r you always put it in the
    best way

  • @amirtayarani7740
    @amirtayarani7740 9 лет назад

    Thanks for your comprehensive videos.
    May i have access to source code. Is there any place to download source code for this tutorial.

  • @ArunKumar-wj4yj
    @ArunKumar-wj4yj 9 лет назад

    Thanks a lot. Nice tutorial for beginners.

  • @nagadurga4140
    @nagadurga4140 9 лет назад

    thank u sir....brilliant explanation..

  • @sonalijadhav9555
    @sonalijadhav9555 4 года назад

    Thank you so much for great knowledge🙏🙏

  • @twentyeightO1
    @twentyeightO1 2 года назад

    Pure gold! Thank you.

  • @Doctor.Fortnite
    @Doctor.Fortnite 8 лет назад

    Thank you so much bro. It helped me a lot

  • @AbhinandanSharmaiisc2017
    @AbhinandanSharmaiisc2017 9 лет назад

    excellent explanation god job !!!!

  • @boli7171
    @boli7171 7 лет назад

    Thank you so much, I understand and works on my code

  • @user-cx7xo2vj8o
    @user-cx7xo2vj8o 2 года назад

    Best explanation to reverse a linked list... Thanks so much.

  • @mukeshpathak7302
    @mukeshpathak7302 8 лет назад +2

    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?

  • @insofcury
    @insofcury 3 года назад

    Thank you for the beautiful explanation

  • @rtnjo6936
    @rtnjo6936 4 года назад +1

    amazing explanation! ty! hello from 2020)

  • @cheems08213
    @cheems08213 4 года назад

    Thank you so much Animesh!

  • @vijayank3207
    @vijayank3207 8 лет назад

    THANK YOU SO MUCH SIR.....nice teaching......

  • @deepeshdragoneel3351
    @deepeshdragoneel3351 4 года назад

    you are just awesome! Thanks for the video!

  • @nirakrish2898
    @nirakrish2898 8 лет назад

    Thank you so much , this video helped me alot

  • @keithprice7119
    @keithprice7119 3 года назад

    Thanks for the very clear explanation.

  • @sharatmalkhed7543
    @sharatmalkhed7543 6 лет назад

    comparision between the time complexity in iterative and recuression methods....

  • @mahammedhashish9170
    @mahammedhashish9170 2 года назад

    Very Good explanation, Thankyou

  • @sandippaul2165
    @sandippaul2165 6 лет назад

    great explain..thank you

  • @mujahidulislam315
    @mujahidulislam315 3 года назад

    Why don't you come back !!
    That the greatest you tube channel of all time for coding.

  • @MaryKateBlack
    @MaryKateBlack 10 лет назад +1

    Thanks, I finally get it.

  • @mohitsaraswat8504
    @mohitsaraswat8504 6 лет назад

    Sir very good explanation helped a lot for my exam

  • @justtop4786
    @justtop4786 5 лет назад +3

    Thank you so much man ❤🙏🙏

  • @akankshamishra7941
    @akankshamishra7941 3 года назад

    Wonderful explanation

  • @shashankshekharismd
    @shashankshekharismd 11 лет назад

    *(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!

  • @vnnmichael
    @vnnmichael 11 лет назад +1

    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

  • @suyash.01
    @suyash.01 3 года назад

    Very well explained!

  • @aliazizi8770
    @aliazizi8770 5 лет назад +1

    Your video was so helpful
    It also works in Java
    Thanks!!!

    • @bipinjaiswal5654
      @bipinjaiswal5654 5 лет назад

      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

  • @shivakumar-lv6wr
    @shivakumar-lv6wr 6 лет назад

    Very nice!. Ek Baar mein samajh aagaya

  • @srisoftengg
    @srisoftengg 4 года назад

    simple and nice but valuable 13 minutes in my life Thanks

  • @victortang94
    @victortang94 8 лет назад

    great video, thank you very much

  • @aswathyjagadeesh
    @aswathyjagadeesh 2 года назад

    Thank you so much Sir!!!

  • @kfircohen9688
    @kfircohen9688 6 лет назад

    you are very good
    keep going like that !

  • @killabyt3
    @killabyt3 Год назад

    Thank you this helped me understand better

  • @mycodeschool
    @mycodeschool  11 лет назад

    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.

  • @abdulkerimyalcn3911
    @abdulkerimyalcn3911 3 года назад

    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

  • @sharmavikas2
    @sharmavikas2 11 лет назад

    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....

  • @satyarthvimal2271
    @satyarthvimal2271 2 года назад

    Best explanation

  • @usama57926
    @usama57926 6 лет назад

    amazing tutorial

  • @rishabhagarwal1947
    @rishabhagarwal1947 7 лет назад

    please tell what changes do we have to do in the original insert and print functions

  • @atharvadeshmukh6367
    @atharvadeshmukh6367 6 лет назад

    NICE tutorial Thanks

  • @suvamroy9426
    @suvamroy9426 9 лет назад

    sir please upload a video to copy a stack to another stack withouth using third temporary stack

  • @LamNguyen-nm1id
    @LamNguyen-nm1id Год назад

    it's like taking a walk in the past, very nostalgic lecture

  • @sanjitjena4954
    @sanjitjena4954 Год назад

    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.