目录 函数 定义 库函数 定义 介绍 Example 1 strcpy Example 2 memset 自定义函数 Example 1 Example 2 两数交换 链式访问 Example 1 函数声明 函数递归 Example 1 Example 2 函数迭代 Example 3 Example 4 总结 函数...
网站建设
C++变量引用的概念介绍
本篇介绍的变量引用与之前介绍的指针不是同一概念,它们有本质的区分: 1)不存在空引用。引用必须连接到一块合法的内存。 2)一旦引用被初始化为一个对象,就不能被指向到另一...
一篇文章带你了解C语言:入门基础
目录 C语言本身特点 数据类型 常量变量 变量分类 使用小建议 生命周期作用域 常量分类及其特点 字符串+转义字符+注释 字符串 转义字符 两种注释 选择循环语句 函数 数组 总结 闲话少...
C++实现LeetCode(179.最大组合数)
[LeetCode] 179. Largest Number 最大组合数 Given a list of non negative integers, arrange them such that they form the largest number. Example 1: Input: [10,2] Output: "210" Example 2: Input: [3,30,34,5,9] Output: "9534330" Note:The res...
一篇文章带你了解C语言:入门基础(2)
目录 操作符 算术操作符 移位操作符 位操作符 单目操作符 逻辑反操作! 操作符++,-- 逻辑操作符 条件操作符 逗号表达式 常见关键字 typedef extern static 修饰局部变量 修饰全局变量和函...
C++索引越界的解决方法
目录 1. 动态数组 2.静态数组 避免"索引越界"错误的规则如下(针对C++): 不要使用静态或动态分配的数组,改用array或vector模板 不要使用带方括号的new和delete操作符,让vector模板为多...
一篇文章带你了解C++多态的实现原理
目录 虚函数和多态 多态的作用 多态的一个例子 构造函数和析构函数中存在多态吗? 多态的实现原理 虚函数表 虚析构函数 纯虚函数和抽象类 总结 虚函数和多态 虚函数: 在类的定义...
C语言简单实现三子棋游戏
本文实例为大家分享了C语言简单实现三子棋游戏的具体代码,供大家参考,具体内容如下 设计思路 1. 二维数组实现棋盘 2. 设计并打印出棋盘 3. 玩家先手 4. 每一次下棋后判断输赢 首先...
基于C语言利用哈夫曼树实现文件压缩的问题
一、哈夫曼树 具有n个权值的n个叶子结点,构造出一个 二叉树 ,使得该树的 带权路径长度(WPL)最小 ,则称此二叉树为 最优二叉树 ,也称为 哈夫曼树(Huffman Tree)。 注意: 哈夫曼...
一文掌握C++ 智能指针全部用法
目录 一、为什么要使用智能指针 二、auto_ptr 三、unique_ptr 四、shared_ptr 五、weak_ptr 六、智能指针的使用陷阱 七、总结 为什么要学习智能指针? 咳咳,这个问题不是问大家的,是询问我...
C++强制类型转换(static_cast、dynamic_cast、const_cast、
目录 1. c强制转换与c++强制转换 2. static_cast、dynamic_cast、const_cast、reinterpret_cast dynamic_cast const_cast reinterpret_cast 3. c++强制转换注意事项 1. c强制转换与c++强制转换 c语言强制类型转换主要...
C++实现LeetCode(186.翻转字符串中的单词之二)
[LeetCode] 186. Reverse Words in a String II 翻转字符串中的单词之二 Given an input string , reverse the string word by word. Example: Input: ["t","h","e"," ","s","k","y"," ","i","s"," ","b","l","u","e"] Output: ["b","l","u","e","...
C++实现LeetCode(557.翻转字符串中的单词之三)
[LeetCode] 557.Reverse Words in a String III 翻转字符串中的单词之三 Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order. Example 1: I...
C++实现LeetCode(188.买卖股票的最佳时间之四)
[LeetCode] 188.Best Time to Buy and Sell Stock IV 买卖股票的最佳时间之四 Say you have an array for which the i thelement is the price of a given stock on day i . Design an algorithm to find the maximum profit. You may complete at...
C语言版的三子棋游戏
本文实例为大家分享了C语言版三子棋游戏的具体代码,供大家参考,具体内容如下 一、游戏说明 三子棋相信大家都不陌生,小时候经常在纸上画出九宫格就可以直接和小伙伴一起玩,...
C++实现LeetCode(309.买股票的最佳时间含冷冻期)
[LeetCode] 309.Best Time to Buy and Sell Stock with Cooldown 买股票的最佳时间含冷冻期 Say you have an array for which the i th element is the price of a given stock on day i . Design an algorithm to find the maximum profit. You...
示例详解C++语言中的命名空间 (namespace)
目录 前言 1. 命名空间 2. using 指令 3. 不连续的命名空间 4. 嵌套的命名空间 5. 命名空间内变量、函数、全局变量的作用域 5.1 using namespace first_space; 5.2 using namespace first_space::second_space; 总...
浅谈C++类型转换几种情况
目录 0. 类型转换的原理 1. 初始化和赋值时进行的转换 2. 以{}方式初始化时进行的转换(C++11新增) 3. 表达式中的转换 4. 传递参数时的转换 5. 强制类型转换 6. 使用auto让编译器自己推断...
C++实现LeetCode(190.颠倒二进制位)
[LeetCode] 190. Reverse Bits 颠倒二进制位 Reverse bits of a given 32 bits unsigned integer. Example 1: Input: 00000010100101000001111010011100 Output: 00111001011110000010100101000000 Explanation: The input binary string 0000001010010...
C++实现LeetCode(191.位1的个数)
[LeetCode] 191.Number of 1 Bits 位1的个数 Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as theHamming weight). For example, the 32-bit integer '11' has binary representation0000000...
Pipes实现LeetCode(192.单词频率)
[LeetCode] 192.Word Frequency 单词频率 Write a bash script to calculate the frequency of each word in a text file words.txt. For simplicity sake, you may assume: words.txt contains only lowercase characters and space ' ' characters. Eac...
Pipes实现LeetCode(195.第十行)
[LeetCode] 195.Tenth Line 第十行 How would you print just the 10th line of a file For example, assume that file.txt has the following content: Line 1 Line 2 Line 3 Line 4 Line 5 Line 6 Line 7 Line 8 Line 9 Line 10 Your script should outp...
Pipes实现LeetCode(194.转置文件)
[LeetCode] 194.Transpose File 转置文件 Given a text filefile.txt, transpose its content. You may assume that each row has the same number of columns and each field is separated by the' 'character. For example, iffile.txthas the followin...
Pipes实现LeetCode(193.验证电话号码)
[LeetCode] 193.Valid Phone Numbers 验证电话号码 Given a text file file.txt that contains list of phone numbers (one per line), write a one liner bash script to print all valid phone numbers. You may assume that a valid phone number mu...
C++初阶之list的模拟实现过程详解
list的介绍 list的优点: list头部、中间插入不再需要挪动数据,O(1)效率高 list插入数据是新增节点,不需要增容 list的缺点: 不支持随机访问,访问某个元素效率O(N) 底层节点动态开辟,...
C++合并二叉树的思路与示例代码
前言 给定两个二叉树,想象当你将它们中的一个覆盖到另一个上时,两个二叉树的一些节点便会重叠。你需要将他们合并为一个新的二叉树。合并的规则是如果两个节点重叠,那么将他...
C++11智能指针unique_ptr用法使用场景分析
一、概述 C++ 标准模板库 STL(Standard Template Library) 一共给我们提供了四种智能指针:auto_ptr、unique_ptr、shared_ptr 和 weak_ptr,其中 auto_ptr 是 C++98 提出的,C++11 已将其摒弃,并提出了 un...
C语言进阶教程之循环语句缺陷详析
目录 前言 1 循环语句的三要素 2 使用不同循环语句实现六种排列组合 2.1 第一种排列(ABC) 2.2 第二种排列(ACB) 2.3 第三种排列(BCA) 2.4 第四种排列(CBA) 2.5 第五种排列(BAC) 2.6...
c++实现版本层次遍历功能
采用队列实现,BFS,功能:BFS层次遍历打印、按照节点将BFS序列化成一个字符。 #include iostream#include string#include queueusing namespace std;struct TreeNode{ int val; TreeNode* left; TreeNode* right; TreeNode(...
C语言:传值与传址交换整数
目录 传值调用 传址调用 总结 传值调用 要想交换两个整数的值,我们可以自定义一个函数,来实现这个过程。具体代码如下: #include stdio.hvoid Swap1(int x, int y){int z = 0;z = x;x = y;y = z;}in...
C++实现LeetCode(198.打家劫舍)
[LeetCode] 198. House Robber 打家劫舍 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 hou...
C++实现LeetCode(199.二叉树的右侧视图)
[LeetCode] 199.Binary Tree Right Side View 二叉树的右侧视图 Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom. For example: Given the follow...
C++实现LeetCode(201.数字范围位相与)
[LeetCode] 201.Bitwise AND of Numbers Range 数字范围位相与 Given a range [m, n] where 0 = m = n = 2147483647, return the bitwise AND of all numbers in this range, inclusive. For example, given the range [5, 7], you should return 4. C...
C++实现LeetCode(202.快乐数)
[LeetCode] 202.Happy Number 快乐数 Write an algorithm to determine if a number is "happy". A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares of i...
C++实现LeetCode(203.移除链表元素)
[LeetCode] 203.Remove Linked List Elements 移除链表元素 Remove all elements from a linked list of integers that have value val . Example Given: 1 -- 2 -- 6 -- 3 -- 4 -- 5 -- 6, val = 6 Return: 1 -- 2 -- 3 -- 4 -- 5 Credits: Special th...
C++实现LeetCode(237.删除链表的节点)
[LeetCode] 237.Delete Node in a Linked List 删除链表的节点 Write a function to delete a node (except the tail) in a singly linked list, given only access to that node. Supposed the linked list is1 - 2 - 3 - 4and you are given the thi...
C++实现LeetCode(207.课程清单)
[LeetCode] 207. Course Schedule 课程清单 There are a total of n courses you have to take, labeled from0ton-1. Some courses may have prerequisites, for example to take course 0 you have to first take course 1, which is expressed as a pai...
C++手写内存池的案例详解
引言 使用 new expression 为类的多个实例分配动态内存时,cookie导致内存利用率可能不高,此时我们通过实现类的内存池来降低overhead。从不成熟到巧妙优化的内存池,得益于union的分时复...
C++野指针和悬空指针的实现方法
目录 一、野指针 二、悬空指针 2.1 情况一 2.2 情况二 2.3 情况三 野指针和悬空指针是指针中常见的两个概念,本文结合实例讲解来讲解下。 一、野指针 野指针是指尚未初始化的指针,...
C++ throw关键字实现抛出异常和异常规范
目录 一个动态数组的例子 throw 用作异常规范 1) 虚函数中的异常规范 2) 异常规范与函数定义和函数声明 请抛弃异常规范,不要再使用它 在《C++异常入门》一节中,我们讲到了 C++ 异常...
C++异常处理入门(try和catch)
目录 捕获异常 发生异常的位置 开发程序是一项“烧脑”的工作,程序员不但要经过长期的知识学习和思维训练,还要做到一丝不苟,注意每一个细节和边界。即使这样,也不能防止程...
C++实现LeetCode(208.实现字典树(前缀树))
[LeetCode] 208. Implement Trie (Prefix Tree) 实现字典树(前缀树) Implement a trie withinsert,search, andstartsWithmethods. Example: Trie trie = new Trie(); trie.insert("apple"); trie.search("apple"); // returns true trie.search("app"...
C++实现LeetCode(211.添加和查找单词-数据结构设计
[LeetCode] 211.Add and Search Word - Data structure design 添加和查找单词-数据结构设计 Design a data structure that supports the following two operations: void addWord(word) bool search(word) search(word) can search a literal w...
C++实现LeetCode(642.设计搜索自动补全系统)
[LeetCode] 642. Design Search Autocomplete System 设计搜索自动补全系统 Design a search autocomplete system for a search engine. Users may input a sentence (at least one word and end with a special character'#'). Foreach charactert...
C++实现LeetCode(648.替换单词)
[LeetCode] 648.Replace Words 替换单词 In English, we have a concept calledroot, which can be followed by some other words to form another longer word - let's call this wordsuccessor. For example, the rootan, followed byother, which can...
C++实现LeetCode(676.实现神奇字典)
[LeetCode] 676.Implement Magic Dictionary 实现神奇字典 Implement a magic directory withbuildDict, andsearchmethods. For the methodbuildDict, you'll be given a list of non-repetitive words to build a dictionary. For the methodsearch, y...
C++实现LeetCode(692.前K个高频词)
[LeetCode] 692.Top K Frequent Words 前K个高频词 Given a non-empty list of words, return the k most frequent elements. Your answer should be sorted by frequency from highest to lowest. If two words have the same frequency, then the word...
C++实现LeetCode(347.前K个高频元素)
[LeetCode] 347. Top K Frequent Elements 前K个高频元素 Given a non-empty array of integers, return the k most frequent elements. Example 1: Input: nums = [1,1,1,2,2,3], k = 2 Output: [1,2] Example 2: Input: nums = [1], k = 1 Output: [1...
C++实现LeetCode(209.最短子数组之和)
[LeetCode] 209. Minimum Size Subarray Sum 最短子数组之和 Given an array ofnpositive integers and a positive integers, find the minimal length of acontiguoussubarray of which the sum ≥s. If there isn't one, return 0 instead. Example...
C语言实现简易扫雷游戏详解
本文实例为大家分享了C语言实现简易扫雷游戏的具体代码,供大家参考,具体内容如下 一、想要达到的游戏功能: 大家如果想编写一个游戏, 应具备以下的步骤: 1:了解游戏的规则...