Interview question: How to design a blocking queue?

foreword I was asked this question in the interview, and the answer was terrible, so I record it here. The answer at that time was to use the while loop to judge whether it is empty when reading. If so, sleep for a period of time, and then judge again. If it is not empty, read and return. When inserting, use the while loop to judge whether it ...

Posted by Jude on Tue, 17 May 2022 18:42:01 +0300

Data structure and program design of leetcode in the direction of postgraduate entrance examination (miscellaneous articles such as number and stack, including train of thought solutions)

Digital problem 9. Number of palindromes Algorithm idea: 1. First, judge whether x is a negative number. If it is a negative number, it directly returns false without conversion 2. Assign the palindrome number y according to the flashback until Y > = X. at this time, if x = = y | x = = Y / 10, it is the palindrome number, otherwise it ...

Posted by elwadhos on Tue, 17 May 2022 18:01:13 +0300

String reverse order - multiple methods

Reverse the order of strings, taking the string abcdef as an example 1. With additional arrays #include <stdio.h> #include <string.h> int main() { char str[] = "abcdef"; //Find the size of the string, including '\ 0' int sz = strlen(str) + 1; //Dynamic memory allocation, apply for a character array of sz size ...

Posted by zechdc on Tue, 17 May 2022 03:07:02 +0300

Detailed explanation of red and black trees

Red black tree The concept of red black tree Red black tree , is a kind of Binary search tree , but Add a storage bit on each node to represent the color of the node, which can be Red or Black . By limiting the coloring method of each node on any path from root to leaf, the red black tree ensures that no path will be two longer ...

Posted by Easter Bunny on Tue, 17 May 2022 02:24:17 +0300

Summary of UnionFind skills

What is joint search set In computer science, the union query set is a tree data structure, which is used to deal with the merging and query of some Disjoint Sets. A union find algorithm defines two operations for this data structure: Find: determines which subset the element belongs to. It can be used to determine whether two elements belong ...

Posted by Revan on Mon, 16 May 2022 04:03:36 +0300

Redis implements the secondary cache of Mybatis

1, Mybatis cache Like most ORM tier frameworks, Mybatis naturally provides support for L1 and L2 caching. The following is the role and definition of L1 cache and L2 cache. 1. The first level cache is the sqlSession level cache. When operating the database, you need to construct sqlSession object, in which there is a (memory area) data st ...

Posted by ladokha on Sun, 15 May 2022 22:48:08 +0300

Data structure - < naive matching algorithm and optimized KMP matching algorithm >

Concept of string String: a finite sequence of zero or more characters, also known as a string Some strings Empty string( null string),It is zero in length and can be directly represented by two pairs of quotation marks "" The so-called sequence shows that the adjacent characters of the string have the relationship between ...

Posted by AcousticJames on Sun, 15 May 2022 11:32:02 +0300

Simple implementation of linked list in Java

catalogue 1, Simple understanding of linked list 1. What does the linked list look like? 2. What is the node? 2, Code implementation of linked list 1. Construction of nodes 2. Construction of linked list  3. View linked list length 4. Find whether to specify whether the element is in the single linked list 5. Insert an element a ...

Posted by FMB on Sun, 15 May 2022 08:47:29 +0300

Blue Bridge Cup 09th 2018 Provincial Competition C/C++ College Students Group B - Question 2 Clear Code

Test question 2 clear code The glyphs of Chinese characters exist in the font library, and even today, the 16-dot font library is still widely used. The 16-dot font library regards each Chinese character as 16x16 pixel information. And record this information in bytes. One byte can store 8 bits of information, and 32 bytes can store the glyph ...

Posted by misterph on Sun, 15 May 2022 06:56:43 +0300

Linked storage structure -- implementation of one-way linked list (Java)

Data structure - one way linked list preface In the previous chapter, we implemented the linear table using the sequential storage structure. We found that the query efficiency of the linear table is very fast and the time complexity is O(1), but the efficiency of adding and deleting data is relatively low. Based on these problems, th ...

Posted by csueiras on Sun, 15 May 2022 01:28:35 +0300