该题算是比较简单的,思路是定义两个栈,一个做为入栈,一个做为出栈。入队列的话直接将元素压入入栈,出队列的话首先判断出栈是否为空,为空则将入栈中的元素依次压入出栈中,再从出栈弹出元素。
class Queue {
public:
// Push element x to the back of queue.
void push(int x) {
instack.pu...
分类:
其他好文 时间:
2015-07-12 11:22:24
阅读次数:
132
题目:
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 lowest p...
分类:
编程语言 时间:
2015-07-12 11:20:56
阅读次数:
206
Implement the following operations of a queue using stacks.
push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(...
分类:
其他好文 时间:
2015-07-11 16:48:45
阅读次数:
86
题目:
Implement strStr().
Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.
题意:
实现strStr()
返回needle在haystack中第一次出现的位置,如果haystack中不存在needl...
分类:
编程语言 时间:
2015-07-11 09:17:03
阅读次数:
196
Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front o...
分类:
其他好文 时间:
2015-07-11 07:54:35
阅读次数:
116
Implement the following operations of a stack using queues.push(x) – Push element x onto stack.
pop() – Removes the element on top of the stack.
top() – Get the top element.
empty() – Return whether...
分类:
其他好文 时间:
2015-07-10 23:45:02
阅读次数:
146
Implement the following operations of a queue using stacks.
push(x) – Push element x to the back of queue.
pop() – Removes the element from in front of queue.
peek() – Get the front element.
empty() –...
分类:
其他好文 时间:
2015-07-10 23:44:01
阅读次数:
153
做题目的时候需要自己实现strstr函数/************************************************************************/
/* 编写函数IND,让它判断一个字符串是否为另一个字符串的子串的功能,若是则返回第一次出现的起始位置,否则返回0。
/*
/***********************************...
分类:
其他好文 时间:
2015-07-10 19:10:03
阅读次数:
117
在Swift中@selector 直接用 "methodName" 就可以了,如果后面有参数记得加上冒号 "methodName:"
“does not implement methodSignatureForSelector: -- trouble ahead”
“does not implement doesNotRecognizeSelector: -- abort”
如果...
分类:
编程语言 时间:
2015-07-10 19:05:24
阅读次数:
154
题目:
Implement the following operations of a stack using queues.
push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Re...
分类:
编程语言 时间:
2015-07-09 14:41:27
阅读次数:
135