Linked List Data Structure
In this tutorial we will talk about a widely useful Linked List data structure.
Previously, we had tried to implement dynamic lists using arrays
,
but we encountered several issues with its inefficiency in terms of memory usage.
To understand LInked List properly, we first need to understand theses limitations encountered
while trying to implement dynamic lists using arrays
.
So, let's start with a story, imagine a computer's memory (RAM) and imagine that to be represented
as separate partitions where each partition represents a byte
of the memory
and each byte
has its memory-address as well. Let's focus on one region of this RAM's memory address
starting with address 200
.
23: Adding lists
Add lists
Write in a function that takes head of two linked lists, each representing a number. The nodes of the linked-lists contain digits as value. The nodes in the input lists are reversed (i.e. the least significant digit of the number is head).
The function should return the head of the new linked list representing the sum of the input lists. The output should have its digits reversed as well.
1 2 3 4 5 6 7 8 9 10 11 12 13 |
|
Solution
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
|
Discussion
...