Students who have used smart pointers in C + + should be aware of the great convenience that smart pointers can bring to memory management in C + +, but also introduce headaches, such as circular references brought by smart pointers, that have not been well resolved in previous projects. recently participated in the development of Android projects, the Java Memory management has a preliminary understand
Note: This is just an interface.
Added the java. util. Queue interface in Java 5 to support common queue operations. This interface extends the java. util. Collection interface.
When using queue, try to avoid the add () and remove
Atitit. java queue System and custom database-Based queue summary o7t and atitito7t
Atitit. java queue System and custom database-Based queue summary o7t
1. Blocking queue and non-bloc
reserved and cannot be used at this time. Although there is no goto statement to enhance the security of the program, but also bring a lot of inconvenience, for example, I want to be in a certain cycle when the end of a certain step, now can not do this thing. To make up for this flaw, Java provides break,continue and return to implement the jump and interrupt of the control statement.
Break InterruptContinue continuereturn returns
1, Jump control
The queue is a new collection class introduced after JDK 5, which belongs to the members of the Java Collections Framework and is the same level of interface in the collection collection as the List/set. The queue is usually described as a FIFO, not all of which are, for example, priorityqueue in order of precedence (or natural order, with comparator interface).D
Data Structure queue implementation (JAVA), queue java
For StackElement, see stack implementation.
Package com. lip. datastruture. stack; public class Queue Running result:
Use Queue list in Java to implement Queue
The Queue list provides methods to support Queue behavior and implements the Queue interface. Therefore, the Queue list can be used as an imple
The queue has a FIFO (first in and out) function, then how to implement this function, Hehe, Java has provided us with Api--queue, following an example to understand the API:Import Java.util.queue;import Java.util.linkedlist;public class Testqueue {public static void Main (string[] args) { queueThe API also has two "get but not remove this
) {///If there is only one element in the queue, then the R The ear points to the head node rear = front;} Size--;return node.element;} Get the opponent element, do not delete public Object Getfront () {if (IsEmpty ()) {return null;} else {return front.next.element;}} The elements in the print queue public void traverse () {if (IsEmpty ()) {System.out.println ("null"),} else {node current = front.next;//Th
① first of all, the GC inside the JVM is used in the root algorithm, the root algorithm, what is called the root, that is, the static members of the class, static members is the type static decoration, is the "root" of one, the root also includes the member variables in the method, only members or objects are not hanging on the root, GC when it is possible to get rid of them, referred to in the circular reference, see if the
Message Queue, Message Queue java
When designing a message queue, we used double buffering to keep one read thread and one write thread !! The read thread operates on read_list and the write thread operates on write_list to keep the complete row of a queue!
For example, if y
, with a constructor below: Public link () { thisnull; }The head node is created, and when the object references the tool class, the head node is defined, so here's a way to create a circular list: Public voidFun () {Scanner s=NewScanner (system.in); System.out.print ("Please enter a list length, enter as a pure number:"); intValue =Integer.parseint (S.nextline ()); Person P=NULL; First=NewPerson (n--);//It must be the first one to be built,
static void Main (string[] args) {
//seek 1-100 and
int sum = 0; Defines the variable sum, which is used to store the sum of the value
int i = 1; The definition of
the variable i do {//does is the dry
//system.out.println ("i =" + i); Loop body statement
sum +=i;
i++;
}
while (i
Output result: Sum = 5050
Summary: The difference between three kinds of
As with stacks, we can also use a single-linked list to implement queue ADT. Similarly, for efficiency reasons, we will use the first (last) node of the single-linked list as the first (last) node of the queue?? This avoids the inefficiency of the single-linked list in the tail-delete operation. In addition, two instance variables are required to indicate the first and stub points of the table, respectively
__kfifo_out_peek (struct __kfifo *fifo, void *buf, unsigned int len) {unsigned int l
;
L = fifo->in-fifo->out;
if (Len > L) len = l;
Kfifo_copy_out (FIFO, buf, Len, fifo->out);
return Len; }
It can be seen from the above, whether it is int, out, or to determine whether the queue is empty/full, there is no lock, there is no CAs, so can do this because of 2 prerequisites:(1) Only 1 read 1 write, one operation in, one operation out(2)
algorithm, O (n) - Public intLength () { to inti = 0; + for(Node This. Head.next; P! = This. Head; p =p.next) -i++; the returni; * } $ Panax Notoginseng //returns the element I (≥0) and returns NULL,O (n) if i - PublicT Get (inti) { the if(I >= 0) { +Node This. Head.next; A for(intj = 0; P! = This. Head J ) thep =P.next; + if(P! = This. Head) - returnP.data;//p points to the first node $ } $
++) {
if (i==2) {
break outer2;
Break
}
System.out.println ("now The value of J is:" +j);
} System.out.println ("******************");
}
Results:Begin to Itrate. 0Now the value of J is:0Now the value of J is:1******************Begin to Itrate. 1Now the value of J is:0Now the value of J is:1******************Begin to Itrate. 2Note: from the results can be seen when the i=2, the break+ tag directly to the inner and outer layers of the loop to Stop. And if we use break alone,
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.