- 博客(24)
- 收藏
- 关注
原创 【C++】顺序表
#pragma once#include#include using namespace std;typedef int DataType;class SeqList{public: SeqList() :_array(NULL) ,_size(1) ,_capacity(1) {} SeqList(DataType* array, size_t size)
2016-04-25 23:01:14
590
原创 【C++】引用计数
#include using namespace std;class String{public: String(const char* str) :_str(new char[strlen(str) + 5]) { _str += 4; strcpy(_str, str); _GetRefCount(_str) = 1; } String(const
2016-04-22 13:06:37
379
原创 【C++】复数类
#include using namespace std;class Complex{public: //构造函数 Complex(double real = 0.0, double image = 0.0) :_real(real) ,_image(image) {} //拷贝构造函数 Complex(const Complex& c) :_real(c._re
2016-04-19 20:42:51
342
原创 【C++】String类
#include using namespace std;class String{public: //String() // :_str(new char[1]) //{ // _str[0] = '\0'; //} String(char* str = "")//构造函数 :_str(new char[strlen(str)+1]) { strcpy(_str
2016-04-18 14:20:48
376
原创 【C++】模拟实现new[]和delete[]
定位new表达式是在已分配的原始内存空间中调用构造函数初始化一个对象。new (place_address) typenew (place_address) type(initializer-list)place_address必须是一个指针,initializer-list是类型的初始化列表。#include using namespace std;clas
2016-04-17 16:00:41
386
原创 【C++】输入输出运算符的重载
#include using namespace std;class Date{ friend ostream& operator<<(ostream& os, Date& d); friend istream& operator>>(istream& is, Date& d);public: Date(int year = 1900, int month = 1, int day
2016-04-13 20:45:05
387
原创 【C语言】链表 题
Slist.h#pragma once#include #include #include typedef int DataType;typedef struct ListNode{ DataType data; struct ListNode *pNext;}SListNode, *PSListNode;//初始化单链表(对于无头结点单链表,该函数没有意义)vo
2016-04-10 21:03:48
641
原创 【C语言】单链表
SList.h#pragma once#include #include #include typedef int DataType;typedef struct ListNode{ DataType data; struct ListNode *pNext;}SListNode, *PSListNode;//初始化单链表(对于无头结点单链表,该函数没有意义)vo
2016-04-09 15:15:11
352
原创 【C语言】顺序表
SeqList.h#ifndef SEQ_LIST#define SEQ_LIST#include typedef int DataType;#define MAX_SIZE 10typedef struct SeqList{ DataType arry[MAX_SIZE]; size_t Size;}SeqList, *pSeqList;//初始化顺序表voi
2016-04-03 19:02:45
385
原创 【C语言】通讯录
Contact.h#define _CRT_SECURE_NO_WARNINGS 0#ifndef __CONTACT_H__#define __CONTACT_H__#include #include #include #include #define MAX_NAME 20#define MAX_SRX 5#define MAX_TELE 12#define MA
2016-03-13 17:48:21
1248
原创 【C语言】实现字符串右移位函数
请实现字符串右移位函数,比如:"abcdefghi"循环右移2位就是"hiabcdefg"。函数原型:void RightLoopMove(char *str, unsigned short steps)函数参数说明:pStr: Point to a '\0' terminated string.steps: The rotate shift numbers.①暴力移位法:
2016-03-08 00:51:50
9541
原创 【C语言】实现对一个8bit数据(unsigned char)类型的指定位的置0或置1操作,并保持其他位不变
功能:实现对一个8bit数据(unsigned char)类型的指定位(例如第n位)的置0或置1操作,并保持其他位不变。函数原型:void bit_set(unsigned char *p_data, unsigned char position, int flag)函数参数说明:p_data是制定的源数据,position是指定位(取值范围1~8),flag是置0还是置1操作#inc
2016-03-07 23:33:35
1770
原创 【C语言】编写函数判断当前的机器大小端模式
大端模式,是指数据的 高 字节保存在内存的 低 地址中,而数据的 低 字节保存在内存的 高 地址中;小端模式,是指数据的 高 字节保存在内存的 高 地址中,而数据的 低 字节保存在内存的 低 地址中。
2016-01-21 00:44:31
474
原创 【C语言】使用main函数的参数,实现一个整数计算器
使用main函数的参数,实现一个整数计算器,程序可以接受三个参数,第一个参数“ - a”选项执行加法,“ - s”选项执行减法,“ - m”选项执行乘法,“ - d”选项执行除法,后面两个参数为操作数。例如:输入test.exe - a 1 2 ,执行1 + 2输出3。
2016-01-21 00:34:15
2985
原创 【C语言】写冒泡排序可以排序多个字符串。
#include #include void bubble_sort_str(char *str[],int sz){ int i = 0; int j = 0; for (i = 0; i < sz - 1; i++) { for (j = 0; j < sz - 1 - i; j++) { if (strcmp(*(str + j), *(str + j + 1)
2016-01-21 00:15:44
1973
原创 【C语言】实现strcat函数
#include #include char *my_strcat(char *dst, const char *src){ assert(dst); assert(src); char *ret = dst; while (*dst != '\0') { dst++; } while (*src != '\0') { *dst = *src; dst++;
2016-01-17 23:13:29
462
原创 【C语言】实现strcpy函数
把从src地址开始且含有NULL结束符的字符串复制到以dest开始的地址空间。src和dest所指内存区域不可以重叠且dest必须有足够的空间来容纳src的字符串。#include #include char *my_strcpy(char *dst, const char *src){ assert(dst); assert(src); char *ret = dst; w
2016-01-17 23:04:39
625
原创 【C语言】实现memcopy、memmove函数
memmove用于从src拷贝count个字符到dest,如果目标区域和源区域有重叠的话,memmove能够保证源串在被覆盖之前将重叠区域的字节拷贝到目标区域中。但复制后src内容会被更改。但是当目标区域与源区域没有重叠则和memcpy函数功能相同。
2016-01-17 22:36:38
384
原创 【C语言】字符串替换空格:请实现一个函数,把字符串中的每个空格替换成“%20”。
字符串替换空格: 请实现一个函数,把字符串中的每个空格替换成“%20”。例如输入“we are happy.”,则输出“we%20are%20happy.”。
2016-01-15 22:29:07
1258
原创 【C语言】有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student".
有一个字符数组的内容为:"student a am i",请你将数组的内容改为"i am a student".要求:不能使用库函数。只能开辟有限个空间(空间个数和字符串的长度无关)。
2016-01-14 16:54:32
2161
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人