A linked list is a linear way to structure the data so that any arbitrary number of data we can store. That means it's flexible on the memory limitation as compare to arrays.
A linear data structure is where I can go to only one other element from the current one.
One supposes you already have two linked lists and they are already sorted how do you merge it effectively? What I mean by being effective is how can you swap the node in memory of a list without having to manage an extra dummy node?
Let go through each method one by one.
The first two are simple. The
Push will add value at the tail of the linked list.
As promised since both linked lists are sorted then the expected output is very simple to guess.
result value is what we will be returning to the caller. At the start, there isn't any result so that's why keeping it
source are pointers to a struct pointer. The value of
dest will be a
nil value because of
lastPtrRef = &((*lastPtrRef).next). In this function what happening is, we're setting the last value to the next node of the sorted list while doing that we're also updating the
result variable. We're also clearing the value which should be removed from the top of the sorted list.