Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Computer Science Introduction to Data Structures Building a Linked List Inserting a Node

Jordan Kittle
seal-mask
.a{fill-rule:evenodd;}techdegree seal-36
Jordan Kittle
Full Stack JavaScript Techdegree Graduate 20,147 Points

Confusing visualization at 3:41 with the position variable and list head

At 3:41, the video animation starts highlighting the tail of the list and going backwards, but previously in the video we learn that we are reducing the position variable every time we called current.next_node, starting with current at the head. This animation is super confusing. Why is it highlighting the tail of the list? Counting down to zero stops at 3 and counting down to 1 stops at 2. When visualizing this from the tail going backward these numbers make no sense either. It only makes sense if, like stated earlier in the video, each time current.next_node is called the position is counting down. Then stopping at 0 would reach 3 and stopping at 1 would reach 2. It seems like we should be highlighting the head and going forward and not the tail going backward.

1 Answer

Chris Freeman
MOD
Chris Freeman
Treehouse Moderator 68,423 Points

Hey Jordan Kittle, you are correct! The example you mention at 341 should be counting down position starting at the head (leftmost) node and proceeding to the right. Instead it is incorrectly highlighting the tail and working toward the head. As a proof of this error, the video discusses that one cannot access the previous node in a singly-linked list. So how then would one traverse from the tail toward the head!?!

The position variable seems to be misnamed. Since index passed in is defined as the offset from the head node, and position is decremented at each stop down the list, "position" is really "number of steps yet to move", so "steps" or "offset" seems a better choice.

Flagging post as feedback!