卡片游戏:很好地介绍了队列的特点和应用
桌上有一叠牌,从第一张牌开始从上往下依次编号1~n。当至少还剩两张牌时进行如下操作:把第一张牌扔掉,然后把新的第一张牌放到整叠牌的最后。输入n,输出每次扔掉的牌,以及最后剩下的牌。
样例输入:7
样例输出:1 3 5 7 4 2 6
代码如下:
#include
#include
using namespace std;
queue q...
分类:
其他好文 时间:
2014-06-16 22:08:57
阅读次数:
220
数组构造二叉树并打印本文地址: http://blog.csdn.net/caroline_wendy数组:构造二叉树, 需要使用两个队列(queue), 保存子节点和父节点, 并进行交换;打印二叉树, 需要使用两个队列(queue), 依次打印父节点和子节点, 并进行交换;二叉树的数据结构:struct BinaryTreeNode {
int m_nValue;
BinaryTreeNod...
分类:
其他好文 时间:
2014-06-16 19:45:17
阅读次数:
373
题目
Implement strStr().
Returns a pointer to the first occurrence of needle in haystack, or null if needle is not part of haystack.
方法
只需要遍历一遍即可。
public String strStr(String...
分类:
其他好文 时间:
2014-06-16 19:07:08
阅读次数:
188
题目
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.
If such arrangement is not possible, it must rearrange it as the low...
分类:
其他好文 时间:
2014-06-16 18:48:33
阅读次数:
170
/**
*1.在Java5中新增加了java.util.Queue接口,用以支持队列的常见操作。该接口扩展了java.util.Collection接口。
*
*Queue使用时要尽量避免Collection的add()和remove()方法,而是要使用offer()来加入元素,使用poll()来获取
*或移除的元素。他们的优点是通过返回值..
分类:
其他好文 时间:
2014-06-16 15:01:35
阅读次数:
218
MySQL为了保护数据字典元数据,使用了metadata lock,即MDL锁,保证在并发的情况下,结构变更的一致性。MDL锁的加锁模式和源码上的组织上和上一篇blog中MySQL表锁的实现方式一致,都采用了【mutex+condition+queue】来实现并发,阻塞,唤醒的控制。下面就来看看MD...
分类:
数据库 时间:
2014-06-16 13:12:51
阅读次数:
383
上一篇介绍了MySQL源码中保护内存结构或变量的锁,这里开始介绍下MySQL事务中的表锁。注1: 在表锁的实现上面,使用【mutex+condition+queue】的结构实现并发,阻塞,唤醒的表锁功能。注2: 本文进行的一些实验,重要的配置项:1. autocommit=02. tx_isol.....
分类:
数据库 时间:
2014-06-15 09:36:39
阅读次数:
250
C规则涉及到 队列(QUEUE) 分类器(CLASS) 过滤器(FILTER),filter划分的标志位可用U32或iptables的set-mark来实现 ) 一般是"控发"不控收 linux下有两块网卡,一个eth1是外网,另一块eth0是内网.在eth0上做HTB。(注 意:filter划分标...
分类:
系统相关 时间:
2014-06-14 15:35:43
阅读次数:
359
#include
#include
using namespace std;
struct Node{
int x, y;
friend bool operator b.x; //x最小的节点在队首
}
};
int main(){
priority_queue PQ;
Node temp = {2, 3};
PQ...
分类:
其他好文 时间:
2014-06-14 14:03:20
阅读次数:
355
//在外面加一圈非0,再广搜
#include
#include
using std::queue;
int t, w, h, arr[962][1442];
int mov[][2] = {-1, 0, 0, 1, 1, 0, 0, -1};
queue Q;
bool check(int x, int y){
if(x h + 1 || y > w + 1)
return 0;...
分类:
其他好文 时间:
2014-06-14 10:06:32
阅读次数:
276