Next: Inserting a new element
Up: Unit 12
Previous: Creation and linking of
Suppose that we have already created a linked list in memory, and that a
variable lis of type ListNode contains a reference to the
first element of the list.
We can perform various operations on such a list. The most common operations
are:
- checking whether the list is empty;
- accessing a node to modify it or to obtain the information in it;
- traversing the list to access all elements (e.g., to print them,
or to find some specific element);
- determining the size (i.e., the number of elements) of the list;
- inserting or removing a specific element (e.g., the first
one, the last one, or one with a certain value);
- creating a list by reading the elements from an input stream;
- converting a list to and from an array, string, etc.
Note that some of the operations above do not modify the list at all, some
modify only the information field of a node, and some modify the structure of
the list, by changing how the nodes are connected to each other.
We will realize each operation through a static method:
- The method takes as one of its parameters a reference to the first node
of the list.
- If the method modifies the list, it also returns a reference to the first
node of the modified list as its return value.
Next: Inserting a new element
Up: Unit 12
Previous: Creation and linking of