Jon Rumsey

An online markdown blog and knowledge repository.


Project maintained by nojronatron Hosted on GitHub Pages — Theme by mattgraham

Lets Get Physical With Data Structures And Algorithms

Host

JB Tellez, long time developer (since Windows 95 days).

Linked Lists

LL Depiction and How To Think About Them

Think of LL Nodes as playing cards, for example a 3-Node LL:

How To Reverse a Linked List?

Could be an interview question! Very difficult to do, strategies vary. Easy to overthink the solution.

Strategies

Make a small change to the current state to get closer to the final state:

Advice: Ed Y. recommends running the process forward AND backwards to ensure the original list is the final result.

Strictly: You can only reference Nodes while Current.Next is not null.

  1. Set Upcoming Node to Head.Next.
  2. Set Head.Next to null.
  3. Set Previous to Head.
  4. Set Current to Upcomming.
  5. Set Upcoming to Current.Next.
  6. Set Previous to Current, Current to Upcoming, to Upcoming.Next.
  7. Continue until Current Node is null.

Resources

From Ed Y.: Relevant Video on YouTube
From Ed Y.: Linux Kernel - Better Way(s) to iterate through a Linked List LWN.net