Subido por Antonio Lara Gutiérrez

application test

Anuncio
Using a linked list type instead
of a vector type
ANTONIO LARA GUTIÉRREZ
When we got a collection of items, and we want to operate them in an easier way
than creating and initializing a complete collection of different variables, we can create
what we now as an array or vector. Depending on the programming language we are
focusing on, the basic goal of an array is to store multiple values of the same type in a
single structure. Thus, we can have an Integer array (collection of integers), String array
(collection of Strings) …
Now we got the idea of a vector, the language must provide the structure itself,
and for that, we have a lot of options, depending on complexity, way of use,
scalability… The main ones we are going to treat in this essay are:
-
Array/vector: simple data structure (in fact, some authors don’t recognize it
as a new data structure) which stores the values in successive memory space.
They are all the same type, and the structure must be initialized with a length
(absolute or relative):
“double [5]”
8.78
-
0
-4.45
7.986
-75.36
Linked List: more complex data structure. It works like an array, and it
consists of a collection of nodes. Each node contains two objects: the value
of the node from the Linked List type and a link to the next node. So, we can
see the next structure:
“LinkedList<Double> ()”
8.78
0
-4-45
As both options can create the same list of elements, the main difference can be
observed in the methods we can access using one solution or another. However, Linked
List has more complexity to implement than vectors. So, why would we go to the
complexity of building a Linked List?
Using a Linked List has bigger benefits than working with array types. Even
though they are more memory-consuming and have more space and time complexity,
using them would provide our work with an excellent tool for storing data. This
structure can create a list that can be expanded at any time (their length isn’t fixed as
with arrays); we can insert, search, and delete any node in an easier and less complex
way, as memory allocation is done in the run time (we don’t need to allocate a fixed
amount of memory in compile time). Finally, the time spent in developing this data
structure will help us in creating other data structures like Stacks or Trees.
For all of this, I widely recommend creating a Linked List structure (using the
Node class from Java and generic types should be enough), from which we can benefit
in many aspects of our future developments!
References
Geeks for Geeks. (12-11-2018). Is an array a primitive type or an object in Java? Obtenido de
https://www.geeksforgeeks.org/array-primitive-type-objectjava/#:~:text=In%20Java%2C%20there%20is%20a,the%20interfaces%20Cloneable%20
and%20java.&text=In%20the%20Java%20programming%20language%2C%20arrays%2
0are%20objects%20(%C2%A74.3.
Oracle. (n.d.). Java SE Documentation. Retrieved from Class LinkedList<E>:
https://docs.oracle.com/javase/7/docs/api/java/util/LinkedList.html
Descargar