Predict the output of the following program? 1 #include<iostream> 2 using namespace std; 3 4 class Empty 5 { 6 }; 7 8 int main() 9 { 10 cout << sizeof(Empty) << endl; 11 return 0; 12 } Output: 1 Size of an empty class is not zero. It is…
关于两个的区别,首先size()==0为bool表达式,empty()为函数调用,这一点很明显.查看源代码, bool empty() const { return _M_node->_M_next == _M_node; } size_type size() const { size_type __result = ; distance(begin(), end(), __result); return __result; } 可以看出empty直接检查标记节点,而size是通过求首尾迭代器的…
队列queue: push() pop() size() empty() front() back() push()  队列中由于是先进先出,push即在队尾插入一个元素,如:可以输出:Hello World! queue<string> q; q.push("Hello World!"); q.push("China"); cout<<q.front()<<endl; pop() 将队列中最靠前位置的元素拿掉,是没有返回值的vo…
1.为什么C++中不允许类的大小是0 class ZeroSizeT {}; ZeroSizeT z[10]; &z[i] - &z[j]; 一般是用两个地址之间的字节数除以类型大小而得到的,而类型大小是0将会出问题 2.为什么有时多个类组成实例所占空间都是一样的 class Empty { }; class EmptyToo : public Empty { }; class EmptyThree : public EmptyToo { }; sizeof(Empty) : 1 size…
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() -- Return whether the queue is empty. Notes: You…
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 the stack is empty. Notes: You may assume that…
Note: This is an extension of House Robber. After robbing those houses on that street, the thief has found himself a new place for his thievery so that he will not get too much attention. This time, all houses at this place are arranged in a circle.…
You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent houses have security system connected and it will autom…
82. Remove Duplicates from Sorted List II https://leetcode.com/problems/remove-duplicates-from-sorted-list-ii/ 下面代码是自写hashmap版,练一下hashmap,用一般的map<int,int>红黑树map也能过. /** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *…
很不好想的一道题,参考:http://blog.csdn.net/doc_sgl/article/details/11832965 分为两步:把原矩阵转为直方图,再用largest rectangle求解:http://www.cnblogs.com/573177885qq/p/5537334.html int largestRectangleArea(vector<int>& heights) { stack<int> s; heights.push_back(); ;…