
c/c++学习
虚荣的梦境
这个作者很懒,什么都没留下…
展开
-
双向链表的基本操作
#includeusing namespace std;typedef struct DNode{ int data; DNode *left; DNode *right;};//建立双向链表DNode*creatlist(int num){ DNode *head,*p; head=(DNode*)malloc(sizeof(DNode)); head->left=he原创 2015-05-27 19:17:23 · 658 阅读 · 0 评论 -
线性表的顺序存储结构
/顺序存储结构的线性表#includeusing namespace std;//线性表的存储结构#define maxsize 20typedef int elemtype;typedef struct{ elemtype data[maxsize]; int length;}splist;//获取线性表的一个元素typedef GetElem(s原创 2015-08-10 21:09:51 · 522 阅读 · 0 评论 -
C++修饰构造函数的explicit关键字
C++ explicit关键字的作用主要是用来修饰类的构造函数,表明该构造函数是显式的,禁止单参数构造函数的隐式转换。如果C++类的构造函数有一个参数,那么在编译的时候就会有一个缺省的转换操作:将该构造函数对应数据类型的数据转换为该类对象,如下面所示:class MyClass{public: MyClass(int num);}MyCla原创 2015-05-25 16:28:28 · 2411 阅读 · 0 评论 -
斐波那契实现
//打印前40位斐波那契数列的实现#includeusing namespace std;int fbi(int i){ if(i<2) { return i==0?0:1; } else { return fbi(i-1)+fbi(i-2); }}int main(){ //非递归方式 /*int a[40]; a[0]=0; a[1]=1; cout原创 2015-06-01 16:31:11 · 580 阅读 · 0 评论 -
编程实现队列的入队、出队、测长、打印
//使用单链表实现队列的入队、出队、测长、打印#includeusing namespace std;typedef int elemtype; typedef struct node{ elemtype data; node *next;}node;typedef struct queue{ node *front; node *rear;}queue;//构造空的原创 2015-06-01 20:52:50 · 1184 阅读 · 0 评论 -
字符串复制
//不用库函数实现字符串复制#includeusing namespace std;void strcopy(char *str1,char *str2){ while(1) { *str2=*str1; str1++; str2++; if(*str1==NULL) { *str2='\0'; break; } }}int mai原创 2015-05-18 16:53:07 · 585 阅读 · 0 评论 -
将数字字符串转化为数字
//字符串转换为数字#includeusing namespace std;int strtonum(char *p){ int temp=0; int flag=0; if(*p=='-') { p++; flag=1; } while(*p!=0) { temp=temp*10+(*p-'0'); p++; } if(flag) return -原创 2015-05-18 16:23:58 · 867 阅读 · 0 评论 -
栈的链式存储结构及简单实现
//栈的链式存储结构#includeusing namespace std;typedef int ElemType;typedef struct stacknode{ struct stacknode *next; ElemType data;};struct stacklist{ stacknode *top; int count;};void InitStack(原创 2015-05-28 17:19:28 · 757 阅读 · 0 评论 -
堆栈的顺序存储结构的简单实现
#includeusing namespace std;//定义一个大小是100的栈typedef int elemtype;//栈的数据结构typedef struct{ elemtype *base; elemtype *top; int size;} sqstack;//初始化堆栈void InitStack(sqstack &S,int size){ S.ba原创 2015-05-28 15:51:58 · 875 阅读 · 0 评论 -
单链表的操作
#includeusing namespace std;//节点结构体typedef struct Node{ int data; Node *next;}Node;//创建单链表Node *Creatlist()//返回指针值的函数{ Node*head,*p,*q; int i=0; head=(Node*)malloc(sizeof(Node)); while(1原创 2015-05-21 22:25:42 · 590 阅读 · 0 评论 -
单循环链表
#includeusing namespace std;struct node{ int data; struct node* next;};struct node*creat(){ node*head,*p,*q; int i=0; head=(node*)malloc(sizeof(node)); while(1) { int x; cout<<"请输原创 2015-05-27 15:51:23 · 670 阅读 · 0 评论 -
结构体字节对齐
结构体字节对齐 结构体字节对齐 在用sizeof运算符求算某结构体所占空间时,并不是简单地将结构体中所有元素各自占的空间相加,这里涉及到内存字节对齐的问题。从理论上讲,对于任何 变量的访问都可以从任何地址开始访问,但是事实上不是如此,实际上访问特定类型的变量只转载 2015-07-21 20:24:45 · 523 阅读 · 0 评论