- 博客(22)
- 资源 (1)
- 收藏
- 关注
转载 尾递归 - Tail Recursion
尾递归是针对传统的递归算法而言的, 传统的递归算法在很多时候被视为洪水猛兽. 它的名声狼籍, 好像永远和低效联系在一起.尾递归就是从最后开始计算, 每递归一次就算出相应的结果, 也就是说, 函数调用出现在调用者函数的尾部, 因为是尾部, 所以根本没有必要去保存任何局部变量. 直接让被调用的函数返回时越过调用者, 返回到调用者的调用者去.以下是具体实例:线性递归:lo
2008-07-30 10:15:00 4213
原创 快速排序
#includevoid swap(int *a, int *b){ int temp=*a; *a=*b; *b=temp;}int partition(int a[],int low,int high){ int i=low-1; int j=low; for(;j { if(a[j]>=a[high]) {
2008-07-29 10:04:00 3997 1
原创 tableau problem
Problem 1: Young tableauAn m × n Young tableau is an m × n matrix such that the entries of each row are in sorted orderfrom left to right and the entries of each column are in sorted order from top to
2008-07-27 15:45:00 3919
转载 内存调试系列
http://www.ibm.com/developerworks/cn/linux/l-cn-memleak/index.htmlhttp://www.ibm.com/developerworks/cn/aix/library/au-memorytechniques.html
2008-07-25 11:53:00 3763
转载 程序的链接和装入及Linux下动态链接的实现
http://www.ibm.com/developerworks/cn/linux/l-dynlink/index.html#N1014C
2008-07-25 11:36:00 4024
原创 堆排序(1)
Analyzing the course,There are 2 points must to be take care: 1 : max_heapify() cost O(lgn) time,build_heap cost O(n).so we can say that the total runing time is O(nlgn). But is not a tigh
2008-07-25 11:13:00 3768
原创 中文字符
#include#include#includeint main(){ //char *a=(char*)malloc(100*sizeof(char)); char c; char a[100]; int i=0; while((c=getchar())!=EOF) { a[i++]=c; } a[i]=/0; i=0;
2008-07-25 10:46:00 3778
原创 gcc编译程序崩溃了!
程序如下:#includevoid escape(char *s,char *t){ char *toend=s; while(toend!=/0) toend++;//to the end of source while(t!=/0) { switch(*t) { case /t:
2008-07-24 12:10:00 4590 4
原创 htoi函数
#include#include/* 方案一,模拟KR书本的atoiint hexalpha_to_int(int c){ char hexalpha[] = "aAbBcCdDeEfF"; int i; int answer=0; for(i=0;answer==0&&hexalpha[i]!=/0;i++) if(hexalpha[i]==c
2008-07-23 11:35:00 12475
转载 位运算
在计算机程序中,数据的位是可以操作的最小数据单位,理论上可以用“位运算”来完成所有的运算和操作。一般的位操作是用来控制硬件的,或者做数据变换使用,但是,灵活的位操作可以有效地提高程序运行的效率。C语言提供了位运算的功能, 这使得C语言也能像汇编语言一样用来编写系统程序。 位运算符C语言提供了六种位运算符: & 按位与 | 按位或 ^ 按位异或 ~ 取反 >> 右移
2008-07-23 11:31:00 3958
转载 c F&A
The questions answered here are divided into several categories: 1. Declarations and Initializations 2. Structures, Unions, and Enumerations 3. Expressions 4. Pointers 5. Null Pointers 6. Array
2008-07-21 10:13:00 7951
原创 寻找逆序对
/* * Let A[1...n] be an array of n distinct numbers,If ia[j], * then pair(i,j) is called an inversion of A .This program determies * the number of inversions of n elements in o(nlgn) worst-case time
2008-07-19 10:12:00 3820
原创 bubblesort
void bubblesort(int a[],int size){ int i,j,temp; for(i=0;i for(j=size-1;j>i;j--) if(a[j] { temp = a[j]; a[j]=a[j-1]; a[
2008-07-19 08:53:00 3697
原创 binary search
int binarysearch(int a[],int value,int l,int h){ int middle; if((l>=h)&&a[l]!=value) return -1; middle=l+(h-l)/2; if(value==a[middle]) return middle; if(value retu
2008-07-18 20:56:00 3786
转载 Horner's rule
Horners Rule for Polynomials A general polynomial of degree can be written as <!-- MATH /begin{equation}P(x) = a_0 + a_1 x + a_2 x^2 + ... + a_n x^n = /sum_{i=0}^n a_i x^i/end{equation}
2008-07-18 10:43:00 8512
原创 归并排序
#include#include#include"common.h"void Merge(int a[],int p,int q,int r){ int l_len=q-p+1; int r_len=r-q; int *L= (int *)malloc((l_len+1)*sizeof(int)); int *R= (int *)malloc((r_len+1)*size
2008-07-17 11:32:00 3835 1
原创 插入排序
#include#include"common.h"int iarray[SIZE];//非递归版本void insert_sort(int a[],int size){ int i,j; int key; for(j=1;j { key=a[j]; i=j-1; while(i>0 && key {
2008-07-17 11:31:00 3619
原创 文本替换小程序
using System;using System.Collections.Generic;using System.Text;using System.Text.RegularExpressions;using System.IO;using System.Data;using System.Data.OleDb;namespace replace{ cl
2008-07-15 17:07:00 4354
转载 移位操作
(1)unsigned char x=3; x>1是多少? (2)char x=3; x>1是多少? (3)char x=-3; x>1是多少? 3写成二进制数是00000011;-3写成二进制数是(补码)11111101。 程序执行的时候,操作的是数值的编码表示,也就是数值在内存中的二进制表示。比如说,程序取-3的时候,就去取1111110
2008-07-15 10:13:00 3673
原创 引用局部变量地址
#include "stdio.h"int *p = NULL;int *fFun(void){int i = 0;//i要被销毁掉,i的值为多少没有关系。return &i;}void subFun(void){(*p)--;}void gFun(void){int j;for(j = 0;j<10;j++){s
2008-07-14 21:12:00 3794
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人