一些常用演算法實現

2021-09-30 08:22:05 字數 2819 閱讀 9901

cstring newguid()

cstring getdatestr2(ctime t)

//獲取當前日期的字串

cstring getdatestr()

//判斷是否數字,這裡指不包含負號的數字

int isnum(const cstring& str)

if (ch >= '0' && ch <= '9')//數字

continue;

return - 2; //非法字元

}if (ndot > 1)

return - 3;//小數點多於兩個

else if (0 == ndot)

return 1;//整數

else if (1 == ndot)

return 0;//浮點數

return - 1000; //未知錯誤

}//包含符號的數字

int issignnum(const cstring& str)

if (ch >= '0' && ch <= '9')//數字

continue;

else if (ch == '-'&&i==0)

continue;

return - 2; //非法字元

}if (ndot > 1)

return - 3;//小數點多於兩個

else if (0 == ndot)

return 1;//整數

else if (1 == ndot)

return 0;//浮點數

return - 1000; //未知錯誤

}//判斷是否數字

bool isnumber( lpctstr psztext )

//判斷字串是否英文

bool isenglish(const cstring str)

}return   re;  

//vc中判斷是日期的方法

bool isdate( lpctstr psztext )

//計算正整數的位數

int calintbit(unsigned input)

return count;

}cstring zuobiaozhuanhuan(const double& input)

cstring dustr(_t("°")),fenstr(_t("′")),miaostr(_t("″"));

str.format(_t("%d%s%d%s%d%s"),du,dustr,fen,fenstr,miao,miaostr);

return str;

}//輸入範圍

bool scope(const cstring& input)

else if (fenge == 1)

if (isnum(max)!=0&&isnum(max)!=1)

if (cstod(min)>cstod(max))

}return true;

}double getmax(const cstring& input)  

double getmin(const cstring& input)

void setsipbnstatus(int show);

//全屏

void fullscreen(cwnd* pwnd,bool _bmove)

//去掉軟鍵盤按鈕

setsipbnstatus(sw_hide);

}//end of fullscreen

//退出全屏

void exitfullscreen(cwnd* pwnd,bool _bmove)

}//退出上面的全屏,下面的輸入法按鈕不顯示

void exitfullscreenhidesip(cwnd* pwnd,bool _bmove)

}//查詢某乙個字元在字串中的最後索引

int lastindexof(const cstring &str,const char c)

return i;

}//判斷後數是否整除前數

#define   num_zero   1.0e-10  

bool divisibility(const double dividend,const double divisor)

return re;

}//獲取當前系統的時間,返回yyyy-mm-dd hh:mm:ss字串

cstring getcurtime()

//設定軟鍵盤的顯示狀態

void setsipbnstatus(int show)

}bool existfile(const cstring &filename)

else

//分離字串

//strcontent:準備分離的字串,例如:a;b;c;d

//arstring:分離後的陣列

//ncount:陣列大小

//ctoken:分隔符

void splite(cstring strcontent, carray&arrstring, int &ncount, const char &ctoken)

}bool strinarray(const cstring &str,const carray&arrstr)

return false;

}//判斷乙個字串是否在另乙個字串中

bool strinstring(const cstring &becontain,const cstring &strcontent)

//根據螢幕規格載入位圖

void loadbmp(cbitmap* pbitmap,uint nid16,uint nid32)

else

}

一些常用的演算法 php實現

un sort array array for i 0 i 20 i 用於二分查詢 need value end un sort array 插入排序 基本思想 每次將乙個待排序的資料元素,插入到前面已經排好序的數列中的適當位置,使數列依然有序 直到待排序資料元素全部插入完為止。示例 初始關鍵字 4...

一些常用演算法 排序

1.冒泡法 1 比較第乙個數和第二個數,若為逆序a 0 a 1 則交換,以此類推 直到第n 1個數和第n個數比較完為止 第一次氣泡排序,結果最大的數被安置在最後乙個元素位置上。2 對前n 1個數進行第二次氣泡排序,結果使次大的數被安置在n 1的位置上。3 重複上述過程,經過n 1次氣泡排序後,排序結...

常用的一些排序演算法(C 實現)

常用的排序演算法有氣泡排序,選擇排序,插入排序,歸併排序 希爾排序,堆排序等 1 冒泡 氣泡排序就是像旗袍一樣,最大的值逐漸上浮,我的實現方法是採用遞迴的,當然也可以不用遞迴 void bubblesort2 int array,int length if index length 1 bubble...