Chapter 3: List, Stacks and Queues
Chapter 3: List, Stacks and Queues
Chapter 3: List, Stacks and Queues
Common errors:
1. The most common error is when a pointer p is not pointing at a
valid part of memory or if its indirection is illegal; you must make
sure that the pointer is not NULL.
2. The only way to create a record that is not already declared is to
use the malloc command, but if you want to run down a list with a
pointer, it is not appropriate to use it. Also, keep in mind that the
number of calls to malloc should equal the size of the list, plus 1 if
there is a header, otherwise you will not have a working program.
3. The free(p) commando allows the program to reclaim a space that
is no longer usable, but the direction of the pointer does not
change
. It is recommended to free a cell after a deletion so
that intermingled routines and memory does not become a
problem to the efficiency of your program; in order to ensure this
you need to keep a temporary variable set to the cell that is going
to be disposed.
4. The command malloc(sizeof node_ptr) doesnt allocate space for a
structure, only for a pointer.
-
Doubly linked lists: Add an extra field to the data structure, containing a
pointer to the previous cell; this may add space requirement and
doubles the cost for insertion and deletions command, but it also
simplifies your program.
Circularly linked lists: When the last cell keep a pointer back to the first,
can be used with or without a header and with doubly linked lists.
Radix Sort and Multilists: Radix sort is known as card sort; it can be used
to sort numbers out of buckets by certain criteria within a running time
of 0(p(n+b)) and it ensures minimum failure on the program. While
Multilists are used when linking different arrays of lists between each
other, using headers, instead of using circularly linked links or ndimensional arrays when programming; this tool ensures a simple and
speedy code, but it can require memory space.
A stack is a list that can only delete and insert at the end of a list
(top); functions pop and push respectively. They are often known as LIFO
(last in, first out) lists, with pushes as input operations and pop and top,
as output. We must note that pop deletes de last inserted element and
when used on an empty cell it is considered an error in the ATD stack,
while performing a push on an empty cell means an error on the
implementation stack.
To create an empty stack we create a header node and with
make_null we set the pointer to NULL.
-
track of the size of the queue; we must ensure that enqueues are not
larger than the size of the queue