- 博客(31)
- 收藏
- 关注
原创 【数据结构】栈的应用--括号的匹配(c++)
头文件:#pragma once#include #include #include using namespace std;templateclass SeqStack{public: SeqStack(size_t sz = INIT_SZ); ~SeqStack();public: bool empty()const; bool full()cons
2015-05-28 21:03:17 606
原创 【数据结构】循环队列的实现(c++)
头文件:#pragma once#include #include using namespace std;templateclass CQueue{public: CQueue(size_t sz = INIT_SZ); ~CQueue();public: bool full()const; bool empty()const; void show()c
2015-05-28 20:59:59 719
原创 【数据结构】顺序队列的实现(c++)
头文件:#pragma once#include #include using namespace std;templateclass SeqQueue{public: SeqQueue(size_t sz = INIT_SZ); ~SeqQueue();public: bool empty()const; bool full()const; void s
2015-05-28 20:52:09 1163
原创 【数据结构】顺序栈的实现(c++)
头文件:#pragma once#include #include using namespace std;templateclass SeqStack{ public: SeqStack(size_t sz = INIT_SZ); ~SeqStack(); public: bool empty()const; bool full()const;
2015-05-28 20:50:49 2174
原创 【数据结构】双循环链表(c++)
头文件:#pragma once#include #include using namespace std;templateclass List;// 结点类templateclass NodeList{ friend class List;public: NodeList(); NodeList(Type d, NodeList *n = NULL,
2015-05-28 20:43:46 628
原创 【数据结构】双链表(c++)
头文件:#pragma once#include #include using namespace std;templateclass List;// 结点类templateclass NodeList{ friend class List;public: NodeList(); NodeList(Type d, NodeList *n = NU
2015-05-28 20:21:51 527
原创 【数据结构】实现循环链表(c++)
头文件:#pragma once#include using namespace std;templateclass List;// 结点类templateclass NodeList{ friend class List;public: NodeList(); NodeList(Type d, NodeList *n = NULL);priva
2015-05-27 13:30:02 595
原创 【数据结构】实现单链表(c++)
头文件:#pragma once#include using namespace std;templateclass List;// 结点类templateclass NodeList{ friend class List;public: NodeList(); NodeList(Type d, NodeList *n = NULL);priva
2015-05-27 13:18:56 653
原创 【c语言】实现对一个8bit数据(unsigned char 类型)的指定位(例如第n位)置0或者置1操作,并保持其他位不变
// 实现对一个8bit数据(unsigned char 类型)的指定位(例如第n位)置0或者置1操作,并保持其他位不变#include void bit_set(unsigned char *p_data, unsigned char position, int flag){ unsigned c; unsigned char a = 1; a = a << (position
2015-05-19 23:30:03 2282
原创 【c语言】把一个长整型给一个字符指针
// 把一个长整型给一个字符指针,修改的时候只修改了一个字节,结果会是一个很大的随机数// 并不能通过这种方式给长整型赋值1#include void VarInit(unsigned char* pucArg) { *pucArg = 1; return; }int main(){ unsigned long ulGlobal; VarInit((unsigned
2015-05-19 21:11:44 1582
原创 【数据结构】实现顺序表(c语言)
头文件:#ifndef _SEQLIST_H#define _SEQLIST_H#include #define INIT_SIZE 8typedef struct SeqList{ int *base; size_t size; size_t capacity;}SeqList;// 要实现的函数void InitList(SeqList *list);
2015-05-19 00:15:08 1374 7
原创 【数据结构】实现顺序表(c++)
头文件:#pragma once#include using namespace std;template class SeqList{ public: SeqList(size_t sz = INIT_SIZE); ~SeqList(); public: bool isfull()const { return size > capacity; }
2015-05-18 17:46:03 640
原创 【c++】c++格式控制输出简单应用
// c++格式控制输出简单应用// 九九乘法表对齐#include #include using namespace std;int main(){ for (int i = 1; i < 10; i++) { for (int j = 1; j <= i; j++) { //cout << i << "*" << j << "=" << i*j<<'\t';
2015-05-15 22:58:54 500
原创 【c++】函数模板的简单应用
// 函数模板的简单应用#include using namespace std;templateType MAX(Type a, Type b){ return a > b ? a : b;}int main(){ cout (1.1,20) << endl; cout << MAX(10, 20) << endl; cout << MAX((float)2, (f
2015-05-15 20:36:46 550
原创 【c++】深赋值与浅赋值
// 深赋值与浅赋值// 浅赋值,这样的浅赋值会导致程序崩溃,与浅拷贝一个理#include using namespace std;class S_Evaluate;ostream& operator<<(ostream& out, const S_Evaluate &s);class S_Evaluate{ friend ostream& operator<<(ostre
2015-05-15 20:10:29 1993
原创 【c++】浅拷贝与深拷贝
// 浅拷贝与深拷贝// 像这样的浅拷贝会导致程序崩溃,因为同一个空间被释放了两次#include #include using namespace std;class S_Copy;ostream& operator<<(ostream& out, const S_Copy &s);class S_Copy{ friend ostream& operator<<(ostr
2015-05-15 17:11:48 531
原创 【c++】cout重载能不能写成成员函数,若能,写出函数原型,若不能,说明原因
// cout重载能不能写成成员函数,若能,写出函数原型,若不能,说明原因#include using namespace std;// cout做友元class A;ostream& operator<<(ostream &out, const A &a);class A{ friend ostream& operator<<(ostream &out, const A &
2015-05-15 14:35:08 1816
原创 【c语言】期望输出str = hello world 的两种方法
// 期望输出str = hello world 的两种方法#include char *GetStr(char **p){ *p = "hello word"; return *p;}int main(){ char *str = NULL; if (NULL != GetStr(&str)) { printf(" str = %s\n",str); } r
2015-05-11 21:09:31 1922
原创 【c语言】位段赋值的例子
// 位段赋值的例子#include int main(){ unsigned char puc[4]; struct tagPIM { unsigned char ucPiml; unsigned char ucData0 : 1; unsigned char ucData1 : 2; unsigned char ucData2 : 3; }*pstPimDat
2015-05-11 15:33:03 3058
原创 【c语言】结构体大小计算的例子
// 结构体大小计算的例子// 默认对齐数为4#include union tagAAA{ struct { char ucFirst;//1 short ucSecond;//2 char ucThird;//1 }half; short kk;//2}number;struct tagBBB{ char ucFirst;//1 short ucSec
2015-05-11 15:03:19 716
原创 【c语言】自己的strncpy与库里的strncpy区别
// 自己的strncpy与库里的strncpy区别#include #define CHAR char#define ULONG unsigned longCHAR *VOS_strncpy(CHAR *pcDest, const CHAR *szSrc, ULONG ulLength){ CHAR *pcPoint = pcDest; // 对指针进行判空 if ((NU
2015-05-11 14:17:40 1070 2
原创 【c语言】关于+1的各种情况
// 关于+1的各种情况#include //默认对齐数为4// 结构体大小为16struct BBB{ long A1; char A2; char A3; long A4; long A5;};int main(){ struct BBB *p; p = (struct BBB *)0x100000; printf("%x\n", p + 0x1);//p
2015-05-08 21:29:59 1653
原创 【c语言】strlen与sizeof对数组和指针的求法
// strlen与sizeof对数组和指针的求法#include #include int main(){ char *pcColor = "12345678"; char acColor[] = "12345678"; printf("%d\n", strlen(pcColor));//8 求字符串的大小 printf("%d\n", strlen(acColor));//
2015-05-08 21:07:23 1034
原创 【c语言】关于临时变量出其作用域就释放的例子
// 关于临时变量出其作用域就释放的例子#include // 临时变量s出函数作用域就销毁了,该空间里就是随机值unsigned short *sum(unsigned char a, unsigned char b){ unsigned short s = 0; s = a + b; return &s;}int main(){ unsigned short *p
2015-05-08 20:51:36 1853 1
原创 【c语言】有符号数据类型与无符号数据类型的计算
// 有符号数据类型与无符号数据类型的计算#include int main(){ char c;// -128~127 unsigned char uc;//0~255 unsigned short us;// 0~65535 c = 128; uc = 128; // 字符型给短整型赋值有默认的类型提升,前边八位补其符号位 us = c + uc; // us = -
2015-05-08 20:29:02 1178
原创 【c语言】位段大小的计算以及宏的应用
// 位段大小的计算以及宏的应用#include #include #define MAX_SIZE A+Bstruct _Record_Struct{ unsigned char Env_Alarm_ID : 4; unsigned char Paral : 2; unsigned char state; unsigned char avail : 1;}*Env_Ala
2015-05-08 17:43:25 899
原创 【c语言】char无符号超范围的结果
// char无符号超范围的结果#include int main(){ unsigned char a = 200; unsigned char b = 100; unsigned char c = 0; c = a + b; printf("%d %d\n", a + b, c); // c是无符号char,范围0~255,300超范围了,所以结果为44 return
2015-05-08 17:18:04 2549
原创 【c语言】小端存储的举例及联合的应用
// 小端存储的举例及联合的应用// 小端存储即低位存在低地址处,内存里即3839// 以short的k读出来即3839#include int main(){ union { short k; char i[2]; }*s, a; s = &a; s->i[0] = 0x39; s->i[1] = 0x38; printf("%x\n", a.k); ret
2015-05-08 16:58:34 528
原创 【c语言】字符0跟'\0'是不一样的
// 字符0跟'\0'是不一样的#include int main(){ int i; char acNew[20]; for (i = 0; i < 5; i++) { acNew[i] = '0'; } printf("%d\n", strlen(acNew)); //结果会是个随机值,strlen遇到\0才会停,遇到‘0’是不会停的 return 0;}//
2015-05-08 16:47:01 1334
原创 【c语言】sizeof里边放数组名,传首元素地址
// sizeof里边放数组名,传首元素地址#include void example(char acHello[]){ printf("%d\n", sizeof(acHello)); return 0;}int main(){ char acHello[] = "hello,tu_lun"; example(acHello); return 0;}
2015-05-08 16:31:26 1200
原创 【c++】实现运算符的重载
// 实现运算符的重载#include using namespace std;class Int{ public: Int(int i = 0) :m(i) { cout << "constructed function" << endl; } ~Int() { cout << "destructor" << endl; } public:
2015-05-08 16:19:13 787
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人