原创 程序清單5.1 forloop.cpp

// forloop.cpp -- introducing the for loop #include <iostream> int main() { using namespace std; int i;

原创 程序清單5.3 express.cpp

// express.cpp -- values of expressions #include <iostream> int main() { using namespace std; int x; cout

原创 C++自定義排序

C++自定義排序 #include <iostream> #include <algorithm> #include <vector> using namespace std; bool compare1(const int&

原创 C++最小堆/最大堆的構造

C++最小堆/最大堆的構造 // 使用 priority_queue, #include <queue> // priority_queue 優先隊列,底層數據結構就是紅黑樹。默認是降序排列,所以本身就是一個最大堆。 #incl

原创 LeetCode 25. K個一組翻轉鏈表

LeetCode 25. K個一組翻轉鏈表 /* struct ListNode { int val; ListNode* next; ListNode(int x) : val(x), next(nullptr) {}

原创 C++ 產生隨機數

C++產生隨機數 // rand(), srand(), time() // 編譯之後,每次運行產生的隨機數是一樣的 #include <iostream> #include <cstdlib> // rand()和srand

原创 程序清單5.18 textin3.cpp

檢測到EOF後,cin將兩位(eofbit和failbit)都設置爲1。linux將ctrl + d視爲EOF。 // textin3.cpp -- reading chars to end of file #include <iost