Data structure arrays, linked lists, stacks, queues appreciated

data structure

Data structure refers to the presence of one or more specific mutual relationship between data elements set. Then briefly describe: a data structure that is subject logical relationships between objects are described.

Data storage structure

Common data storage in two ways: sequentially storing, non-sequential storage. Is sequentially stored in a link to a storage medium (memory, hard disk or the like) is stored in. Otherwise a non-sequential storage.

Array in Java is typically stored in order, the list is non-sequential storage. It will open up a contact when the memory array to store data, stored sequentially. The list does not carve out a first memory to, but only needs to know the location of the next node storage, so the data will be able to connect up. So-way linked list of the last node is pointing to Null

Arrays, linked lists, queues, and the stack is the most basic data structures, program language will involve any one of them or more

Array

An array is a data structure is the basic structure of many programming languages ​​have built-in array.

It will be divided in java when creating an array in memory a contiguous memory, and when data will be entered when data is stored in contiguous order in this memory. When the data needs to be read in the array, the array need to provide an index, and the index array will take out the data in memory, the program returns to the reader. In Java, not all data can be stored in an array, only the same type of data can only be stored in the array together

All data structures are supported by several basic operations: read, insert, delete.

Because the data is stored in the array sequentially stored in memory for storing data is continuous, so he is characterized by addressing the data easier to read, insert and delete more difficult . Briefly explain why, when reading data, only need to tell the array from which location (index) will be able to fetch data, the array will direct the data you want to take out your location. Insertion and deletion is difficult because the data stored in memory is continuous, it is necessary to insert and delete data to change the location of the entire array. For example: a number array 0-> 1-> 2-> 3-> 4 in which five memory addresses are stored in the data array, but now you need to insert the data into a 4, it represents from 4 starts, all data in memory to be moved back one place behind. This is very time-consuming.

List

Process to create lists of different processes in java and create an array, not the first to draw a contiguous memory. Because the data is not continuous linked list, there are two regions in the linked list memory to store data, an area for storing data, an area used to record the data stored where (a data pointer pointing to the next). When data enters the chain when the stores will locate the next pointer based on the data, and the saved data, and then point to the next location for storing data. Such list put up some of the debris space utilization, though the list is a linear list, but will not linearly sequentially stored data.

Since the list in this way to save the data, so the list is easier when inserting and deleting, more trouble when reading data. For example: a list of 0-> 1-> 2-> 3-> 4 in which five memory address data are stored, and now needs to be inserted into a data 2, then only need to change the No. 1 and No. 2 record the next location of the data on the line, no effect on other data. Delete data and insert a similar, very efficient. But if you want to remove the data in a linked list in which you need to find one by one starting from 0 until you find the piece of data you want.

Stack

The latter stack is advanced out of the data structures, arrays, and can generate a list stack. When data enters the stack will be pressed into the bottom follow the rules of the stack, the data is again pressed into the first of the above data, and so on.

Remove the top sheet will first data when the data out of the stack, it is the last out.

Because arrays and linked lists are composed of the stack, so the operation will need to look at the characteristics of the stack is generated by an array or list, then the appropriate action will inherit characteristics.

queue

A queue is a FIFO data structure, the array can also be generated and linked list queue. When the data enters the queue is the first entry in the following re-enter the top, but when the queue is to start out below, then the above data is out, the latest entry in the queue, and finally out.

As a simple example: the stacks and queues can be viewed as two tubes, two tubes which are used to store data, there may be an array generated list may also be generated, which stack tubes there is a sealed, so as to put this data only from a tube into the mouth, when the data can only come from a mouth out. The queue of this pipe does two ports are open, into a port responsible for data, the other port is responsible for the data, imports from the advanced to the data at the exit will be first out.

 

Guess you like

Origin www.cnblogs.com/woxbwo/p/11518198.html