Over 10 Million Study Resources Now at Your Fingertips
Rating : ⭐⭐⭐⭐⭐
Price : $10.99
be placed upon the programmer; there should be only
one function. Pretend there is, and always use memmove.
We could replace the memmove call with the following loop:
Next to arrays, lists are the most common data structure in typical
programs. Many languages have built-in list types-some, such as Lisp,
are based on them-but in C we must build them ourselves. In C++ and
Java, lists are implemented by a library, but we still need to know how
and when to use it. In this section we're going to discuss lists in C
but the lessons apply more broadly.
There are several important differences between arrays and lists.
First, arrays have fixed size but a list is always exactly the size it
needs to be to hold its contents, plus some per-item storage overhead to
hold the pointers. Second, lists can be rearranged by exchanging a few
pointers. which is cheaper than the block move necessary in an array.
Finally, when items are inserted or deleted the other items aren't
moved; if we store pointers to the elements in some other data
structure, they won't be invalidated by changes to the list.
Login Your Account
Add to Cart
Page 1 Preview