
C++
C++
权律三爸爸
研究生 东南大学
展开
-
malloc与new方法动态创建数组并释放
#includeusing namespace std;int main(){//动态创建释放一维数组(new)int *a;//基地址int n=10;//数组大小a=new int[n];//创建 delete[] a;//释放//动态创建释放二维数组(new)int **b;int m=10;n=10;b=new int*[m];for(原创 2016-04-01 23:17:31 · 2023 阅读 · 0 评论 -
循环队列
#include#includeusing namespace std;#define max 5typedef int Qelemtype;typedef struct {Qelemtype *base;int front;int rear;}queue;int Init(queue &Q){Q.base=(Qelemtype*)malloc(max原创 2016-04-17 22:42:23 · 510 阅读 · 0 评论 -
C++中为什么有时候会出现使用cin后在再使用getchar()会没有用
C++中为什么有时候会出现使用cin后在再使用getchar()会没有用?比如下面这个程序:#includeusing namespace std;int main(){int x;coutcin>>x;char *u=(char*)malloc(x*sizeof(char));coutchar c;c=getchar();int k=0;whi原创 2016-05-05 17:54:51 · 4225 阅读 · 1 评论 -
哈弗曼树,哈弗曼编码,及其翻译
#includeusing namespace std;static char* r;static int v;typedef struct{int weight;int lch,rch,par;}HTNode,*HuffmanTree;typedef char** HuffmanCode;int select( HuffmanTree &T,int m,int原创 2016-05-05 17:57:49 · 576 阅读 · 0 评论 -
友元
/*有些情况下,允许特定的非成员函数访问一个类的私有成员,同时仍阻止一般的访问,这是很方便做到的。例如被重载的操作符,如输入或输出操作符,经常需要访问类的私有数据成员。友元(frend)机制允许一个类将对其非公有成员的访问权授予指定的函数或者类,友元的声明以friend开始,它只能出现在类定义的内部,友元声明可以出现在类中的任何地方:友元不是授予友元关系的那个类的成员,所以它们原创 2017-07-26 21:59:09 · 509 阅读 · 0 评论 -
蓝桥杯—算法训练 最大最小公倍数 (简单贪心思想)
问题描述已知一个正整数N,问从1~N中任选出三个数,他们的最小公倍数最大可以为多少。输入格式输入一个正整数N。输出格式输出一个整数,表示你找到的最小公倍数。样例输入9样例输出504数据规模与约定1 6。题意分析:在n个数中找任意三个数的最小公倍数,并且求得最大的最小公倍数(重点在于最大)。原创 2018-01-31 20:00:03 · 618 阅读 · 0 评论 -
蓝桥杯真题----方格填数
方格填数填入0~9的数字。要求:连续的两个数字不能相邻。(左右、上下、对角都算相邻)一共有多少种可能的填数方案?请填写表示方案数目的整数。注意:你提交的应该是一个整数,不要填写任何多余的内容或说明性文字。思路:明显是一道dfs题答案:1580代码:#include<iostream>using namespace std;int vis[10];int gezi[4][4];int d...原创 2018-03-07 13:02:20 · 697 阅读 · 0 评论 -
算法训练 安慰奶牛
问题描述Farmer John变得非常懒,他不想再继续维护供奶牛之间供通行的道路。道路被用来连接N个牧场,牧场被连续地编号为1到N。每一个牧场都是一个奶牛的家。FJ计划除去P条道路中尽可能多的道路,但是还要保持牧场之间 的连通性。你首先要决定那些道路是需要保留的N-1条道路。第j条双向道路连接了牧场Sj和Ej(1 <= Sj <= N; 1 <= Ej <= N; Sj !...原创 2018-02-28 15:27:55 · 857 阅读 · 1 评论 -
趣谈C++之void是什么?
void关键字的使用规则: 1. 如果函数没有返回值,那么应声明为void类型; 2. 如果函数无参数,那么应声明其参数为void; 3. 如果函数的参数可以是任意类型指针,那么应声明其参数为void * ; 4. void不能代表一个真实的变量;void体现了一种抽象,这个世界上的变量都是“有类型”...转载 2018-02-20 12:55:12 · 30213 阅读 · 0 评论 -
趣谈C++之memchr
先看一下官方做出的解释const void * memchr ( const void * ptr, int value, size_t num ); void * memchr ( void * ptr, int value, size_t num );Locate character in block of memorySearches within the first...原创 2018-02-20 13:27:36 · 884 阅读 · 0 评论 -
C++读取带空格字符串总结
关于在C++中字符串的输入整理笔记1. cincin是C++中最常用的输入语句,当遇到空格或者回车键即停止如:#include <iostream>#include <string>using namespace std;int main(){ chara[50]; cin>>a; cout<<...转载 2018-07-14 09:05:44 · 1445 阅读 · 0 评论 -
单链队列基本操作
typedef int Qelemtype;#define OK 1#define ERROR 0#includeusing namespace std;typedef struct QNode{Qelemtype data;struct QNode *next;}QNode,*QueuePtr;typedef struct{QueuePtr front;原创 2016-04-16 12:46:36 · 638 阅读 · 0 评论 -
循环列表设立头指针和尾指针
#includeusing namespace std;typedef struct Lnode{ int data; struct Lnode *next;}Lnode,*Linklist;int Init(Linklist& L){ L=(Linklist)malloc(sizeof(Lnode)); if(!L)return -1; L->next=L;原创 2016-04-13 12:18:34 · 1630 阅读 · 0 评论 -
稀疏矩阵的十字链表表示法及其加法减法运算算法
#include#includeusing namespace std;#define ERROR -1typedef struct OLNode{int i,j,e;struct OLNode *right,*down;}OLNode,*OLink;typedef struct{OLink *rhead,*chead;int mu,nu,tu;}Cro原创 2016-03-29 18:45:50 · 2096 阅读 · 1 评论 -
串的模式匹配KMP算法
#includeusing namespace std;typedef struct{char*ch;int length;}SString;int Ass(SString &H,char *sh){int i=0;while(sh[i]) i++;H.ch=(char*)malloc((i+1)*sizeof(char));H.leng原创 2016-04-01 13:16:53 · 806 阅读 · 0 评论 -
串的基本操作
#include#includeusing namespace std;#define TRUE 1;#define FALSE 0;#define OK 1;#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2typedef struct {int length;char *ch;}Hstr原创 2016-04-01 10:35:01 · 1147 阅读 · 0 评论 -
链式表逆向输入和顺向输入
#includeusing namespace std;typedef struct Lnode{struct Lnode *next;int data;}Lnode,*Linklist;int Initlist(Linklist &L){L=(Linklist)malloc(sizeof(Lnode));if(!L)return 0;L->next=NULL;原创 2016-03-28 23:43:27 · 1092 阅读 · 0 评论 -
合并顺序表和链式表
#define Listsize 100#define Listincrease 50typedef int elemtype;#includeusing namespace std;typedef struct{//顺序表elemtype *e;int length;int size;}Sqlist;Initsqlist(Sqlist &L){L.原创 2016-03-28 22:28:10 · 1011 阅读 · 0 评论 -
一元多项式加减
#includeusing namespace std;#define OK 1#define ERROR 0#define OVERFLOW -1typedef struct{float coef;int expn;}elemtype;typedef struct Lnode{struct Lnode*next;elemtype data;}Lno原创 2016-03-27 21:51:03 · 711 阅读 · 0 评论 -
C++输出流格式
#include#includeusing namespace std;int main(){int a;coutcin>>a;coutcoutcoutcoutchar *q="LOVE";coutcoutdouble m=7.0/6.0;coutcoutcoutcoutcoutcoutreturn 0;}原创 2016-03-27 09:58:13 · 734 阅读 · 0 评论 -
串的三种实现方式
#includeusing namespace std;#define TRUE 1;#define FALSE 0;#define OK 1;#define ERROR 0#define INFEASIBLE -1#define OVERFLOW -2#define MAXSTRLEN 10typedef struct{unsigned char str[原创 2016-03-27 09:22:33 · 648 阅读 · 0 评论 -
C++编程迷宫
#include #include#define OK 1#define ERROR 0#define OVERFLOW -1#define SIZE 50#define SIZEINCRE 10static int mn=0;using namespace std;typedef struct{int x;int y;}pos;typedef原创 2016-03-24 22:44:47 · 893 阅读 · 0 评论 -
数组的顺序存储表示
//以下构造了大小为3*3*3的3维数组#include#include#define OK 1#define ERROR 0#define OVERFLOW -1typedef int elemtype;using namespace std;typedef struct{int dim;int*bounds;elemtype原创 2016-03-21 22:02:04 · 810 阅读 · 0 评论 -
静态链表
/*用静态链表实现集合A-B∪B-A*/#includeusing namespace std;#define max 100typedef struct{int data;int cur;}component,Slinklist[max];int Initspace(Slinklist&space){for(int i=0;i原创 2016-04-06 13:57:31 · 505 阅读 · 0 评论 -
插入冒泡选择以及折半法排序
#includeusing namespace std;typedef struct{int length;int *e;}shuzu;int Init(shuzu &L){L.e=new int[6];L.e[0]=0;L.e[1]=23;L.e[2]=46;L.e[3]=37;L.e[4]=50;L.e[5]=14;L.length=6;原创 2016-04-06 22:26:35 · 629 阅读 · 0 评论 -
C++入门第一课
First Part尝试第一个程序:#include <iostream>using namespace std;int main(){ cout << "Hello world!" << endl; return 0;}Second PartTThird Part...原创 2019-05-01 07:59:00 · 437 阅读 · 0 评论