Answer the question
In order to leave comments, you need to log in
How to implement adding an element to a unidirectional list?
Can you please tell me how to implement the add to list method with a header element?
The list is unidirectional, the heading is _first, the insertion point is returned by the search function (Temp=Search(sname);). The problem is how to put the data from Temp.Next into _first after the found element.
Answer the question
In order to leave comments, you need to log in
Something I do not understand what is the problem. Can't be compared? In the same place, in fact, a simple algorithm - you find the element after which you need to insert an element, if the link to the next one is empty, then you simply hang a link to the element being inserted, if it is not empty, then you make the link to the inserted element equal to Temp.Next, and Temp.Next should point to inserted element.
In the same place, in fact, only the first element of the list is needed, but the last one can be inserted at the end of the list for simplicity. But the list elements themselves contain a value and a link to the next element of the list. And insertion and deletion are simply reassigning links to the next element.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question