
C和C++程序员面试秘籍
C++的一些面试题
alike_meng
好菜啊,怎么办
展开
-
文件排序输出
#include<iostream>#include<fstream>#include<vector>using namespace std;void Order(vector<int>& data){ int count = data.size(); for (int i = 0; i < count; i++) {...原创 2020-02-06 22:42:49 · 166 阅读 · 0 评论 -
STL简介
1.STL Standard Template Library 标准模板库,容纳于C++标准程序库,约占整个库的80%,涵盖常用的数据结构和算法,跨平台、复用。2.STL含有容器、算法、迭代器组件3.STL容器分为序列容器(vector、string、deque、list),关联容器(set、multiset、map、multimap),STL适配容器(stack、queue、priority...原创 2020-02-06 19:15:47 · 131 阅读 · 0 评论 -
带头结点单链表操作(数据结构)
#include<iostream>using namespace std;typedef struct node{ int data; node *next;}node;node* create() //创建单链表,带头结点{ int i = 0; node *head, *p, *q; int x = 0; head = ...原创 2020-02-06 15:42:25 · 551 阅读 · 0 评论 -
COM简介
以下内容是从C和C++程序员面试秘籍上摘抄的笔记1.Component Object Model 组件对象模型的首字母COM,COM是一种技术标准,是组件之间相互接口的规范。2.COM是一种跨应用、跨语言共享二进制代码的方法,提倡代码重用,使各种软件构件和应用软件可以用一种统一的标准方式进行交互。3.COM定义的二进制标准独立于任何编程语言,使得任何变成语言都可以存取它所编写的模块。4.C...原创 2020-02-05 18:40:10 · 1198 阅读 · 0 评论 -
图形类,面向对象设计
#include<iostream>using namespace std;#define PI 3.14159class Shape{public: Shape(){} ~Shape(){} virtual void Draw() = 0; virtual double Area() = 0;};class Rectangle :public Shape{...原创 2020-02-05 18:13:36 · 368 阅读 · 0 评论 -
计算一个数的二进制中有几个bit是1
#include<stdio.h>#define BIT31 (0x1<<31) int calculate(unsigned int c){ int count = 0; int i = 0; unsigned int comp = BIT31; for (i = 0; i < sizeof(c) * 32; i++) { if (...原创 2020-02-02 21:32:07 · 2080 阅读 · 0 评论 -
反转字符串,指定子串不反转
#include<iostream>#include<cassert>#include<stack>using namespace std;const char* reverse(const char* s1, const char* token){ stack<char> stack1; const char* ptoken = t...原创 2020-02-02 16:30:18 · 272 阅读 · 0 评论 -
两个字符串的最大公共子串
#include<iostream>#include<cstring>using namespace std;char *commonstring(char *str1, char *str2){ char *shorts, *longs; char *sub; if (str1 == NULL || str2 == NULL) return NULL;...原创 2020-02-01 18:17:37 · 390 阅读 · 0 评论 -
字符串中单词置逆
#include<iostream>using namespace std;char* RevStr(char *src){ char *start = src, *end = src, *ptr = src; while (*ptr++ != '\0'); end = ptr - 2; //end指向句子的最后一个字母 while (st...原创 2020-01-28 18:21:07 · 203 阅读 · 0 评论 -
手写strstr
#include<iostream>#include<cassert>using namespace std;const char *strstr(const char* src, const char* sub){ const char *bp; const char *sp; if (src == NULL || sub == NULL) { re...原创 2020-01-28 13:48:07 · 255 阅读 · 0 评论 -
手写strlen
#include<iostream>#include<cassert>using namespace std;int strlen1(const char* src){ assert(src != NULL); int len = 0; while (*src++ != '\0') len++; return len;}int strlen2(c...原创 2020-01-28 13:21:27 · 299 阅读 · 0 评论 -
手写memcpy函数
#include<iostream>#include<cassert>using namespace std;void *memcpy2(void *memTo, const void *memFrom, size_t size){ assert((memTo != NULL) && (memFrom != NULL)); char *temp...原创 2020-01-28 12:03:21 · 905 阅读 · 0 评论 -
手写strcpy函数
#include<iostream>using namespace std;char* strcpy(char *strSrc, char *strDest){ if ((strSrc == NULL) || (strDest == NULL)) return NULL; char *strDestCopy = strDest; while ((*strDest++ ...原创 2020-01-26 18:54:48 · 1384 阅读 · 0 评论 -
字符串转化为数字
#include<iostream>using namespace std;int str2int(const char *str){ int temp = 0; const char *ptr = str; if (*str == '-' || *str == '+') str++; while (*str != 0) { if ((*str) < '...原创 2020-01-26 18:05:44 · 170 阅读 · 0 评论 -
整数转化为字符串
#include<iostream>using namespace std;void int2str(int n, char *str){ char buf[10] = " "; int i = 0; int len = 0; int temp = n < 0 ? -n : n; if (str == NULL) return; while (temp)...原创 2020-01-26 16:14:22 · 542 阅读 · 3 评论 -
指针数组和数组指针
#include<iostream>using namespace std;int main(){ int x1[4] = { 1,2,3,4 }; int x2[2] = { 5,6 }; int x3[3] = { 7,8,9 }; int *a[2]; int *b = x1; int i = 0; a[0] = x2; a[1] = x3; c...原创 2020-01-04 11:24:39 · 102 阅读 · 0 评论 -
指针加减操作
#include<iostream>using namespace std;int main(){ int a[5] = { 1,2,3,4,5 }; int *ptr = (int*)(&a + 1); cout << *(a + 1) << endl; cout << *(ptr - 1) << endl; ...原创 2020-01-02 10:57:30 · 173 阅读 · 0 评论 -
指针和引用的区别
初始化引用:创建时就要初始化,指向一个有效的对象指针:创建时不必初始化,可以随后赋值 修改引用:指向一个对象就不能再成为另一个对象的引用指针:可以改变指向的对象 NULL引用:不能指向空指针:可以为NULL 测试引用:不指向空,所以不必测试合法性指针:必须测试(因此,引用效率比指针高) 应用引用:针对不改变指向的情况指针:针对有指向NULL和需要...原创 2020-01-01 19:00:32 · 98 阅读 · 0 评论 -
交换字符串
#include<iostream>#include<string>using namespace std;void swap(char* &a, char* &b) //传指针引用,传入的是实参而不是形参,所以能够实现交换{ char* temp; temp = a; a = b; b = temp;}int main(){...原创 2020-01-01 18:23:19 · 1695 阅读 · 0 评论 -
指针变量引用
#include<iostream>using namespace std;int main(){ int a = 1; int b = 10; int* p = &a; //指针变量p指向a int* &pa = p; //pa是p的指针引用 (*pa)++; //pa指针指向的内容+1,pa是p的引用,p指向的内...原创 2020-01-01 17:53:47 · 312 阅读 · 0 评论 -
转化成大写字母
#include<iostream>#include<string.h>using namespace std;void UpperCase(char str[]){ for (size_t i = 0; i < strlen(str); i++) { if ('a' <= str[i] && str[i] <= 'z'...原创 2019-12-31 13:30:12 · 263 阅读 · 0 评论 -
C++类的静态成员简单理解
#include<iostream>using namespace std;class widget{public: widget() { count++; } ~widget() { --count; } static int num() { return count; }private: static int count;};int ...原创 2019-12-30 11:11:21 · 176 阅读 · 0 评论