|
|
Optimize with a SATA RAID Storage Solution
Range of capacities as low as $1250 per TB. Ideal if you currently rely on servers/disks/JBODs
Last month's column brought you into the computer science world of datastructures and algorithms by focusing on the array datastructure and associated algorithms. Developers view the array as a fundamental datastructure because it serves as the basis for more complex datastructures, such as stacks, queues, and trees. Developers also view the fundamental linked-list datastructure as a foundation for more complex datastructures.
This article wraps up a two-part series that explores datastructures and algorithms. You first learn about the linked-list datastructure in terms of its single, double, and circular variants. While learning those variants, you discover the related linked-list algorithms for node-insertion/deletion, concatentation, inversion, and insertion-sort. I also discuss the advantages and disadvantages of the linked list and array, a rule-of-thumb for deciding when to use each datastructure in your own programs, and whether or not both can integrate into useful hybrid datastructures. Finally, you receive an introduction to the more complex stack, queue, and tree datastructures.
| Note |
|---|
| Though Java supplies its own classes and interfaces to meet many of your datastructure and algorithm needs, you might need a specific datastructure or algorithm that Java doesn't supply. A basic knowledge of those topics should simplify the task of creating that datastructure/algorithm. |
Read the whole series: "Datastructures and Algorithms," Jeff Friesen (JavaWorld)
In addition to the array, another datastructure that receives much use is the linked list. The linked-list datastructure involves four concepts: the self-referential class, node, link field, and link:
class Employee
{
private int empno;
private String name;
private double salary;
public Employee next;
// Other members
}
Employee is a self-referential class because its next field has type Employee.
next is a link field. In contrast, empno, name, and salary are nonlink fields.
next's reference to an Employee node is a link.
The four concepts above lead to the following definition: a linked list is a sequence of nodes that interconnect via the links in their link fields. Computer scientists use a special notation to illustrate linked lists. A variant of that notation, which I use in this article, appears in Figure 1.

Figure 1. A special notation for illustrating linked lists
Figure 1 presents three nodes: A, B, and C. Each node divides into a contents area (in orange) and one or more link areas (in green). The contents area represents all nonlink fields, and each link area represents a link field. A's single link area and C's link areas incorporate an arrow to signify a reference to some other node of the same type (or a subtype). B's single link area incorporates an X to signify a null reference. In other words, B doesn't connect to any other node.