
C++
文章平均质量分 62
shifind
这个作者很懒,什么都没留下…
展开
-
链表操作
#include "stdafx.h" #include using namespace std;struct student{ int data; struct student *next;};// The linked list has a head node which hasnt data, // and assume t原创 2004-08-13 15:41:00 · 979 阅读 · 0 评论 -
string的几个函数
int StrLen(const char* str){ const char *sc; for (sc = str; *sc != /0; ++sc); return sc - str;}char* StrTrim(char* s){ char* pDst = s; while(1) { if (*pDst == || *pDst == /t || *pDst原创 2004-08-01 14:00:00 · 1189 阅读 · 0 评论 -
排序算法
#include void InsertSort(int arr[], int len){ for (int i=1; i { int temp = arr[i]; for (int j=i-1; j>=0 && temp { arr[j+1] = arr[j]; } arr[j+1] =原创 2004-08-13 11:15:00 · 979 阅读 · 0 评论 -
求素数
素数就是大于1,只能被1和它本身整除的正整数。100以内的素数共25个: 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97#include void main(){ int n = 100; int i = 3; int arr[100]; arr[0] = 2;原创 2004-08-17 15:54:00 · 1937 阅读 · 8 评论 -
重载、覆盖与隐藏
重载(overload)用于同一个类中的成员函数,其特征为:(1)相同的范围(在同一个类中);(2)相同的函数名字;(3)参数不同(包括参数类型不同,或参数个数不同,或两者都不同。注意:和返回值没关系);(4)和是否为虚函数无关。覆盖(override)是指派生类函数覆盖基类函数,其特征为:(1)不同的范围(分别位于派生类与基类);(2)相同的函数名字;(3)参数相同(即参数类型和参数个数均相同原创 2006-01-18 19:11:00 · 1329 阅读 · 1 评论 -
查找算法
在这里简单介绍一下哨兵。在很多数据结构书中,对顺序查找使用了哨兵。其实加“哨兵”是早期数据结构中的事,当时的语言工具是汇编级别吧。由于数组是从下标0开始的,我们对arr[0]赋值就改变了这个数组。按照现代软件工程,安全与封装更重要。在目前的Java解决方案中,人们实在懒得再提起此项技术了。所以在下列的顺序查找算法中,并没有使用哨兵。#include int SeqSearch(int ar原创 2006-02-14 15:39:00 · 1084 阅读 · 0 评论 -
统计字符串中各个字符的数量
#include // Count the number of each characterint count[128]; void CountChar(char ch[]){ for (int i = 0; i { count[i] = 0; } int j; for (i = 0; ch[i] != /0; i++) {原创 2006-02-14 16:29:00 · 1708 阅读 · 0 评论 -
判断字符串是否对称
判断字符串是否对称,且不能用字符串的系统函数。#include int StrSymmetry(char *c){ char *x = c; int n=0; while(*x) { x++; n++; } x--; for(int i = 0; i { if(原创 2006-02-14 16:36:00 · 1592 阅读 · 0 评论