The Java collection is broadly divided into set, List, Queue, map four systems
Where set represents an unordered, non-repeatable set, the list represents an ordered, repeating set, and a map represents a collection with a mapping relationship; queue is the implementation of queues.
Collections and arrays are different, array elements can be either primitive types
Offer,add differences:Some queues have a size limit, so if you want to add a new item to a full queue, the extra items will be rejected.At this point the new offer method will work. It does not throw a unchecked exception to the call to the Add () method, but only gets the false returned by the offer ().Poll,remove differences:Both the Remove () and poll () methods remove the first element from the queue. R
Why use a thread pool?
Many server applications, such as WEB servers, database servers, file servers, or mail servers, are geared toward handling a large number of short tasks from certain remote sources. Requests arrive at the server in some way, either through a network protocol (such as HTTP, FTP, or POP), through a JMS queue, or possibly by polling the database. Regardless of how the request arrives, a common occurrence in server applications is
Topic 1: Use a secondary stack and some additional non-array variables to store the elements in the stack s in ascending order.
Topic 2: Use a secondary queue and some additional non-array variables to store the elements in queue Q in ascending order.
1. Java implementation, the first use of linked list LinkedList structure stack data structure.
import java.ut
Java least heap implements priority queue and calculates the maximum n count
Priority queue
Priority queue is a very useful data structure. The process scheduling in the operating system has priority queue applications. If the minimum value represents the highest priority,
Java data structure and algorithm parsing (13)--Priority queue
In many applications, we usually need to deal with the processing object according to the priority situation, such as dealing with the highest priority object first, and then processing the object of the high level. The simplest example is when you play a game on a mobile phone, and if there is a call, then the system should prioritize incoming
As the Java API says:Java.util.PriorityQueue.PriorityQueue ()Creates a with the PriorityQueue default initial capacity (one) that orders their elements according to their natural ordering.The default ordering of priority queue Priorityqueue is the natural order of the elements. Take advantage of this feature and use it as a small top pile to find the first k elements in the array. Packagestructure;ImportJav
LinkedList provides a method to support the behavior of the queue, and it implements the queue interface, so linkedlist can be used as an implementation of the queue.Package Cn.usst.queue.demo;import Java.util.linkedlist;import Java.util.queue;import java.util.random;/* * Basic use of queue */public class Queuedemo {public static void main (string[] args) {queueP
Java implementation stacks and queues
Stack: LIFO (backward first out)
Queues: FIFO (first-in first Out)
Sequential storage structure implementation of stacks:
/** * Based on array implementation of sequential stack * @param
The chain-type storage structure of the stack is implemented:
public class Linkstack
Stack structure based on LinkedList implementation:
Import java.util.LinkedList;
/**
* Based on the LinkedList implementation stack
*
This blog is a previous Java Multithreading (iii) Producer consumer model and the implementation of the method complement. The producer consumer model is implemented in three methods (lock, synchronized, blocking queue). The specific content is: The producer produces the random number (in order to facilitate the reading result, I limit the random number to 10 integers), the consumer reads and prints. 1 blo
Recently in the review of the Java Foundation, looked at the Java Foundation, in the see the collection when suddenly found that the interview has a written question: simulation of a stack or queue data structure, was not done, today to write, the first to understand the stack and the data structure of the queue
Stack:
Input22040Sample Output1 7 191) 19 37Attention:Here to pay attention to the title of the one or two, refers to all the people in order after the completion of the report, and then 123. If you have:First time off one or two: Staff: 1 2 3 4 5 6 7 8 9 10Count off: 1 2 1 2 1 2 1 2 1 2Second off 123: Staff: 1 3 5 7 9Count off: 1 2 3 1 2So cycle the above two steps, knowing that the number of people does not exceed three.There is also a detail in the output is, control the formatting problem, the las
= Tmp.pair;//value pairsList.add (ele);//Join the result set if(TMP.J = = Nums2.length-1) Continue; Queue.add (NewPair (TMP.I,TMP.J + 1,NUMS1[TMP.I],NUMS2[TMP.J + 1])); } returnlist; }}//defining the data structure of a pairclassPairImplementsComparable{ int[] pair =New int[2];//Define Array Pairs inti;// the subscript of the first element in a nums1intJ;// The subscript of the second element in a NUMS2 PublicPair (intIintJintE1,intE2) {pair[0] =E1; pair[1]
element, the last is also assigned as Nulllast = null;} First = first.next;//Set next to Firstreturn temp.ddata;//return to the original first}public void Displaylist (){System.out.println ("List (first-->last):"); Link_long current = first;//is used to continuously change the position implementation traversal while (current! = null) {Current.displaylink (); current = Current.next;}}} Class Name: linkqueue//property://Method: Implement Queue class Li
:===================fixedlist===================//fixed-length queue//can be specified in length, using the same method as the normal queue//when the number of elements to be added to the specified number of elements will pop up//head insertion trailer, Tail Insert Header popup//initialization maximum length is 5fixedlistIt can be seen that it can be operated entirely using the LinkedList method, except tha
Title Description:
N Mice (1
Input:
multiple case inputs, input of each case an integer n, representing the number of mice. There are n rows, each of which is a white mouse message. The first is a positive integer not greater than 100, which represents the weight of the mouse, and the second is a string representing the color of the white mouse's hat, and the string length is no more than 10 characters. Note: The weight of the mice is diffe
Principle:The team is in the tail and the team heads out.RunThere is nothing wrong with popping data from one queue at a time, but there is an error when the data is popped back into the array when the data is inserted again because the font and end are not reset and the next loop queue will solve the problem.Source:public class Myqueue {Private int[] array; Underlying arrayprivate int elements; Number of v
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.