Read about data structures and abstractions with java, The latest news, videos, and discussion topics about data structures and abstractions with java from alibabacloud.com
Arrays are the most widely used data storage structures. It is implanted in most programming languages.Basic knowledge of arrays in JavaCreate an arrayThey are treated as objects in Java, so you must use the new operator to create an array:Int[] Intarray;Defines a reference to an array Ingarray = new int[100]; Creates the array, and//sets int array to refer to it
What is the use of arrays? -When you need to arrange 30 numbers in size, it is a good choice to use data structures such as arrays, and when you are a class head teacher, it is also useful to keep track of the number of absences that students have. Arrays can be inserted, deleted, searched, and so on.1) Creation and memory allocationThere are two data types in
)
Unordered array Delete (query + fill hole)
O (N)
Ordered array deletion (query + fill hole)
O (N)
Why not use data to solve everythingAn unordered array is inserted (O (1) time), and the query spends (O (N) time). An ordered array query spends (O (logn) time), but inserts a missing cost (O (N) time). And the deletion takes (O (N) time). So a data structur
is true. is called a short-circuit operation because if the value of the expression on the left side of is false, the expression on the right will be shorted out directly and will not be evaluated.Most of the time we may need to use instead of , for example, to verify that the user's name is not NULL and is not an empty string when validating the login, it should be written as username! = null !username.equals (""), The order of the two cannot be exchanged,You cannot use the operator, becaus
Common data Structures in JavaCommon data structures are hash tables, linear lists, linked lists, and java.util packages with three important interfaces: List,set,map commonly used to implement basic data structuresHow the HashMap worksHashMap based on the hashing principle,
(); - } - - Public BooleanIsEmpty () {///Bottom call is LinkedList's IsEmpty () method to determine if the set internal data is empty - returnlink.isempty (); in } -}(2) test of Mystack:1 Packagecn.itcast_05;2 3 /*4 * Test of Mystack5 */6 Public classMystackdemo {7 Public Static voidMain (string[] args) {8 //To create a collection object9Mystack ms =NewMystack ();Ten One //adding elements AMs.add ("Hell
right) {//Why J plus a 1, and I do not add 1 because the following loop is judged to start with--j and ++i.// The base element is selected Array[left], that is, the first element, so Zoo starts from the second element to compare int i = left;int J = Right+1;int pivot = array[left];//pivot for the selected datum element (head element) int Si Ze = right-left + 1;if (size >= 3) {pivot = medianOf3 (array, left, right);//array range is greater than 3, the datum element selects an intermediate value.
This article summarizes some of the data structures implemented in JavaBriefly:ListQueuemapSetThe data structure involved:Stack: provides push and stack (POP) functionsqueues: non-blocking methods for offer and pull, blocking methods for put and takeList : provides various functions such as add, find, remove, traverse, etc.Tree: Red-black tree, usually used for r
Analysis of common JAVA data structures and principles
Not long ago, the interviewer asked me to explain how to understand the java data structure framework. I have also read some of the source code before. balabala has talked about a bunch of ideas and I will summarize them
mapping of key-value pairs, the relationship belongs to the inner object in the collection, which has direct access to the elements in the collection. In practical applications I think more of the nesting of maps.The tool class (collections, Arrays) Collections Collection Tool class is an operation combined with a specialized tool class which is defined by a static method, A variety of sorting binary lookups for the list collection (analogy string operations) can also turn threads unsafe into t
: a container for data storage, an array, or a linked list; a pointer; Other API behaviors are all around the container ** The main composition of a queue: a container for data storage, an array of arrays, or a list of two pointers. ** is not suitable for large amounts of storage, just a means of implementing some sort of algorithm.,** Restricted access Mode **@ authorerjun2017 December 6 Morning 9:11:40*/
capacityincrement)
Vector initial capacity is initialcapacity, increment is capacityincrement
The smaller the vector increment set, the higher the utilization of the memory space, but the greater the number of memory allocations
The larger the vector increment is set, the less memory allocation will be performed, but it is possible to generate memory waste
Adding elements to a vector: the Add () method or the Insertelementat () method
After inserting an element, the
methods of collection and traversal mode Collection:add () Remove () contains () iterator () size () Traversal: Enhanced for iterator |--listget () Traversal: normal For|--setmap:put () Remove () ContainsKey (), Containsvalue () KeySet () get () value () EntrySet () size () Traversal: Find values based on key values for key and value jobs: Any collection I've explained, I ask you to store what you are able to store. And, you have to be able to traverse it.4:arraylist,linkedlist,hashset,hashmap
initialization does not require allocating space, but it needs to allocate a pointer field, there is a structural overhead, but there is no length limit.
Application recommendations:?? If the use of the stack element changes unpredictable, sometimes very small, sometimes very large, then it is best to use the chain stack, conversely, if its change in the controllable range, it is recommended to use a sequential stack is better.The reason for using the stack: the introduction of the stack s
more additions and deletions: LinkedList104 query MORE: ArrayList the I don't know, just use ArrayList.106 I don't know, just use ArrayList.107 108 3: Common methods of collection and Traverse mode 109 Collection: the Add ()111 Remove () the contains ()113 iterator () the size () the the Traversal: 117 Enhanced for118 iterators119 -|--List121 get ()122 123 Traversal:124 General for the|--Set126 127 Map: - put ()129 Remove () the Con
Stack implementation of data structures (JAVA) (I)
// Stack top element public class StackElement
{Private StackElement
NextElement; private T data; public StackElement (T data) {this. data =
("Lookup data does not exist"); the return NULL; the } + -System.out.println ("Find successful, data is:" + This. list[p]); the return This. list[p];Bayi } the the //Sequential Table Size - Public intSizeOf () { - return This. Listlen; the } the the Public voidPrint () { theSystem.out.print ("["); - for(inti = 0; I This. list.length;
() method in the Bubblesort.java program (listing 3.1) with the Oddevensort () method . Make sure it runs in a sort of different amount of data, and that you need to figure out the number of two scans. Parity Ordering is actually useful in multiprocessor environments where the processor can process each odd pair at the same time, and then handle even pairs at the same time. Because the odd pairs are independent of each other, each pair can be compar
, this time will not be faster than bubble sorting.Back to top 4, summaryThe above three kinds of sorting, bubbling, selecting, inserting with large O notation all require O (N2) time level. Bubbling sorting is not generally selected, although bubbling sort writing is the simplest, but the average performance is not to choose sort and insert sort well.Select sort to reduce the number of exchanges to the lowest, but the number of comparisons is quite large. Select sort can be applied when the amo
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.