Data Structure: queue and cyclic queue; Data Structure: cyclic queue
Note: Yan Weimin's "data structure" (C language version) takes notes and records them for later viewing.
# Include
During initialization, both front and rear are equal to 0. The number of queue elements is 0.
In this case, the number of
Topic description Use two stacks to implement a queue, complete the queue push and pop operations. The elements in the queue are of type int.import java.util.Stack;public class Solution {Stacknew StackStacknew Stackpublic void push(int node) {int temp = 0;if (stack1.isEmpty()) {stack1.push(node);return;}while(!stack1.isEmpty()){temp=stack1.pop();stack2.push(temp)
Algorithm: Use two stacks to implement a queue, complete the queue push and pop operations. The elements in the queue are of type int. "The sword means offer"The use of the stack to operate, code comments written more clearly: first determine whether the two stack is empty: Second, when the stack is empty, the stack 1 is taken out to stack two, and finally return
Data Structure Java Implementation -- queue's "wonderful" second-priority queue, java queuePreface
In many cases, some data storage not only requires FIFO, but also sorting based on the priority of the data, that is, the priority must first go out, the priority of the same FIFO, in this case, the priority queue is used.
Application
In fact, Priority Queues are widely used. For example, the constru
1. The original question of cattle net:
topic Description Xiao Ming students put 1 to n these n numbers in a certain order into a queue Q. Now he has executed the following procedure for queue Q:
while (! Q.empty ()) //Queue not empty, execute loop
{
int x=q.front (); Remove the value of the current team head x
q.pop ();
;
Public static void main (string [] ARGs) throws interruptedexception {
For (INT I = 1; I
Executorservice executor = executors. newfixedthreadpool (thread_num
* I );
Test ("", Count, 10 * I, executor );
}
System. Out. println ("concurrent1_queue AVG time ="
+ Concurrenttotaltime/totalthreadcount );
System. Out. println ("blocked blockingqueue AVG time ="
+ Define blockingtotaltime/totalthreadcount );
}
}
As a result, it takes 49 milliseconds to run 100,000 concurrent
Implementation of the chain storage structure of the queue 2-calculate the number of elements at the beginning and end of the queue for viewing the queue
// Filename: list_queue.c // Author: LupingChen/Data: 2015.05.30 // Content: create \ destory \ full \ empty \ push # include
Idea: Use Stack1 to implement the queue push operation, with Stack2 to achieve the queue of pop operations, when the Stack2 is empty, the stack1 of the data are all pressed into Stack2, waiting for the queue of pop operations.
Class solution
{public
:
void push (int node) {
Stack1.push (node);
}
int pop () {
int result;
if (S
design patterns:
13, the responsibility chain mode (Chain of responsibility pattern), in which many objects are connected by each object's reference to their house to form a chain. The request is passed on this chain until an object on the chain decides to process the request, which allows the system to dynamically rearrange the chain and assign responsibility without affecting the client.
14, command pattern is to encapsulate a request into an object that allows you to parameterize clients wit
Data structure experiment queue 1: queuing for meals
Time Limit: 1000 ms memory limit: 65536 K
Description
There were a lot of people buying meals at noon, and the dining room was too crowded. It was hard to buy a meal. The children of science and engineering were still very smart. They went straight to Zhengtong supermarket. Haha, indeed, Zhengtong supermarket also sold meals, there are several kinds of dishes, which are much better than the cante
Now say the first two basic concepts, what is the process, what is a thread, what is multi-threaded; Let's get these two to the bottom of the story.Process: An ongoing program, we call it process.Thread: A thread is a separate execution path in a process. How to understand this sentence! A program it is executed sequentially from top to bottom, this execution order we can think of it as a line, the line is called the thread (personal understanding, wr
Functional Requirements:> Given a sentence (containing only letters and spaces), reverses the position of the word in the sentence, divides the word with a space, has only one space between the words, and no space before >.For example: (1) "Hello Xiao Mi", "Mi xiao Hello"-Enter a description:> Input data has multiple groups, one row for each group, including a sentence
In the words of the work of the algorithm is really how??????Although the work is not used, but you have to change work, can't resist the written interview to ask you some of this stuff.Moreover, thinking more can help the mind to be active. The children's shoes can also be active and prevent rusting in the deep plunge into the project.Words do not say much, the topic is as follows:Title: Enter an English sentence, flipping the order of the words in t
The head first design model is an interesting book about design patterns.
Reading books at school is different from reading books at work. At school, we read books for reading. We can go from 0 to 1. We have time. But it is different after work.
I think the book at this time is more like the secret of the martial arts that connects the two sides of my supervision. In my daily work, I learned some things, but they cannot be integrated. Therefore, you need to clarify your ideas through books. This
push to top, peek/pop from top, size, and is empty operations are valid.Depending on your language, stack may not be supported natively. You may simulate a stack by using a list or deque (double-ended queue), as long as you use only standard operations of a stack.You may assume that all operations are valid (for example, no pop or peek operations will be called on an empty queue).
Analysis
As you can see,
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.