15.04.2018 Views

programming-for-dummies

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

340<br />

Using Linked Lists<br />

To delete data from a linked list, you can delete an entire node. Then you<br />

must change the pointers to keep your linked list together, as shown in<br />

Figure 2-9. Unlike arrays, linked lists give you the flexibility to rearrange data<br />

without physically moving and copying it to a new location.<br />

Abby<br />

Bob<br />

Charlie<br />

Danny<br />

Pointer<br />

Pointer<br />

Pointer<br />

Pointer<br />

Abby<br />

Bob<br />

Charlie<br />

Danny<br />

Pointer<br />

Pointer<br />

Pointer<br />

Pointer<br />

Cal<br />

To add data to a linked list, you just<br />

have to rearrange pointers.<br />

Pointer<br />

Figure 2-9:<br />

Adding and<br />

deleting<br />

data from a<br />

linked list<br />

rearranging<br />

pointers.<br />

Abby<br />

Pointer<br />

Bob<br />

Pointer<br />

Charlie<br />

Pointer<br />

Danny<br />

Pointer<br />

To delete data from a linked list, you just have to<br />

rearrange pointers and then delete the node.<br />

Linked lists also let you add data anywhere just by rearranging the pointers<br />

(see Figure 2-9). By using linked lists, you can add, delete, and rearrange<br />

data quickly and easily.<br />

Creating a double linked list<br />

An ordinary linked list contains pointers that point in one direction only.<br />

That means if you start at the beginning of a linked list, you can always<br />

browse the data in the rest of the linked list. However, if you start in the<br />

middle of a linked list, you can never browse the previous nodes.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!