锘??xml version="1.0" encoding="utf-8" standalone="yes"?> UNICODE錛氬畠鏄敤涓や釜瀛楄妭琛ㄧず涓涓瓧絎︾殑鏂規硶銆傛瘮濡傚瓧絎?A'鍦ˋSCII涓嬮潰鏄竴涓瓧絎︼紝鍙?A'鍦║NICODE涓嬮潰鏄袱涓瓧絎?楂樺瓧絎︾敤0濉厖錛岃屼笖姹夊瓧'紼?鍦ˋSCII涓嬮潰鏄袱涓瓧鑺傦紝鑰屽湪UNICODE涓嬩粛鏃ф槸涓や釜瀛楄妭銆俇NICODE鐨勭敤澶勫氨鏄畾闀胯〃紺轟笘鐣屾枃瀛楋紝鎹粺璁★紝鐢ㄤ袱涓瓧鑺傚彲浠ョ紪 鐜板瓨鐨勬墍鏈夋枃瀛楄屾病鏈変簩涔夈?nbsp; WINDOWS涓嬮潰鐨勭▼搴忚璁″彲浠ユ敮鎸丮BCS鍜孶NICODE涓ょ緙栫爜鐨勫瓧絎︿覆錛屽叿浣撶敤 LPTSTR銆丩PCSTR銆丩PCTSTR銆丩PSTR鐨勬剰涔夛細 Windows浣跨敤涓ょ瀛楃闆咥NSI鍜孶NICODE錛屽墠鑰呭氨鏄氬父浣跨敤鐨勫崟瀛楄妭鏂瑰紡錛屼絾榪欑鏂瑰紡澶勭悊璞′腑鏂囪繖鏍風殑鍙屽瓧鑺傚瓧絎︿笉鏂逛究錛屽鏄撳嚭鐜板崐涓眽瀛楃殑鎯呭喌銆傝屽悗鑰呮槸鍙屽瓧鑺傛柟寮忥紝鏂逛究澶勭悊鍙屽瓧鑺傚瓧絎︺俉indowsNT鐨勬墍鏈変笌瀛楃鏈夊叧鐨勫嚱鏁伴兘鎻愪緵涓ょ鏂瑰紡鐨勭増鏈紝鑰學indows9x鍙敮鎸丄NSI鏂瑰紡銆俖T涓鑸悓瀛楀父鏁扮浉鍏籌紝濡俖T("Hello"銆傚鏋滀綘緙栬瘧涓涓▼搴忎負ANSI鏂瑰紡錛宊T瀹為檯涓嶈搗浠諱綍浣滅敤銆傝屽鏋滅紪璇戜竴涓▼搴忎負UNICODE鏂瑰紡錛屽垯緙栬瘧鍣ㄤ細鎶?Hello"瀛楃涓蹭互UNICODE鏂瑰紡淇濆瓨銆俖T鍜宊L鐨勫尯鍒湪浜庯紝_L涓嶇浣犳槸浠ヤ粈涔堟柟寮忕紪璇戯紝涓寰嬩互UNICODE鏂瑰紡淇濆瓨. Windows鏍稿績緙栫▼鐨勭涓绔犮?/p> L鏄〃紺哄瓧絎︿覆璧勬簮涓篣nicode鐨勩?/p> 姣斿 _T鏄竴涓傞厤鐨勫畯锝?/p> 褰?br />#ifdef _UNICODE鐨勬椂鍊?br />_T灝辨槸L 姣斿 LPTSTR lpStr = new TCHAR[32]; T鏄潪甯告湁鎰忔濈殑涓涓鍙鳳紙TCHAR銆丩PCTSTR銆丩PTSTR銆乢T()銆乢TEXT()...錛夛紝瀹冭〃紺轟嬌鐢ㄤ竴縐嶄腑闂寸被鍨嬶紝鏃笉鏄庣‘琛ㄧず浣跨敤 MBCS錛屼篃涓嶆槑紜〃紺轟嬌鐢?UNICODE銆傞偅鍒板簳浣跨敤鍝瀛楃闆?緙栬瘧鐨勬椂鍊欐墠鍐沖畾
MBCS錛屽畠鏄瀛楄妭瀛楃闆嗭紝瀹冩槸涓嶅畾闀胯〃紺轟笘鐣屾枃瀛楃殑緙?銆侻BCS琛ㄧず鑻辨枃瀛楁瘝鏃跺氨鍜孉SCII涓 錛堣繖涔熸槸鎴戜滑瀹規槗鎶奙BCS鍜孉SCII鎼炴販鐨勫師 錛夛紝浣嗚〃紺哄叾浠栨枃瀛楁椂灝遍渶瑕佺敤澶氬瓧鑺傘?nbsp;
閭g灝辯湅瀹氫箟浜哅BCS瀹忚繕鏄疷NICODE瀹忋侻BCS瀹忓搴旂殑瀛楃涓叉寚閽堟槸char*涔熷氨鏄疞PSTR錛孶NICODE瀵瑰簲鐨勬寚閽堟槸unsigned short*涔熷氨鏄疞PWSTR錛屼負浜嗗啓紼嬪簭鏂逛究寰蔣瀹氫箟浜嗙被鍨婰PTSTR錛屽湪MBCS涓嬩粬灝辨槸char*,鍦║NICODE涓嬪畠鏄痷nsigned char*,榪?灝卞彲浠ラ噸瀹氫箟涓涓畯榪涜涓嶅悓瀛楃闆嗙殑杞崲浜嗐?/p>
wchar_t Str[] = L"Hello World!";
榪欎釜灝辨槸鍙屽瓙鑺傚瓨鍌ㄥ瓧絎︿簡銆?/p>
娌℃湁#ifdef _UNICODE鐨勬椂鍊?br />_T灝辨槸ANSI鐨勩?/p>
TCHAR* szBuf = _T("Hello");
浠ヤ笂涓ゅ彞浣垮緱鏃犺鏄湪UNICODE緙栬瘧鏉′歡涓嬮兘鏄紜紪璇戠殑銆?br />鑰屼笖MS鎺ㄨ崘浣犱嬌鐢ㄧ浉鍖歸厤鐨勫瓧絎︿覆鍑芥暟銆?br />姣斿澶勭悊LPTSTR鎴栬匧PCTSTR 鐨勬椂鍊欙紝涓嶈鐢╯trlen ,鑰屾槸瑕佺敤_tcslen
鍚﹀垯鍦║NICODE鐨勭紪璇戞潯浠朵笅錛宻trlen涓嶈兘澶勭悊 wchar_t*鐨勫瓧絎︿覆銆?/p>
LPTSTR鍜孭STR鍖哄埆
LP鍜孭鍦╳in32涓槸絳夋晥鐨勶紝閮芥槸鎸囬拡鐨勬剰鎬濄?nbsp;
PTSTR鐨勫畾涔?nbsp;typedef LPWSTR PTSTR, LPTSTR;
杞澆鑷?/p>
]]>
]]>
鍗籌細
銆銆銆0^0 = 0錛?
1^0 = 1錛?
0^1 = 1錛?
1^1 = 0
渚嬪錛?0100001^00010001=10110000
鎸変綅寮傛垨鐨?涓壒鐐?/font>:
(1) 0^0=0,0^1=1 0寮傛垨浠諱綍鏁幫紳浠諱綍鏁?/span>
(2) 1^0=1,1^1=0 1寮傛垨浠諱綍鏁幫紞浠諱綍鏁板彇鍙?/span>
(3) 浠諱綍鏁板紓鎴栬嚜宸憋紳鎶婅嚜宸辯疆0
鎸変綅寮傛垨鐨勫嚑涓父瑙佺敤閫?/font>:
(1) 浣挎煇浜涚壒瀹氱殑浣嶇炕杞?/span>
渚嬪瀵規暟10100001鐨勭2浣嶅拰絎?浣嶇炕杞紝鍒欏彲浠ュ皢璇ユ暟涓?0000110榪涜鎸変綅寮傛垨榪愮畻銆?/span>
銆銆銆銆銆 10100001^00000110 = 10100111
(2) 瀹炵幇涓や釜鍊肩殑浜ゆ崲錛岃屼笉蹇呬嬌鐢ㄤ復鏃跺彉閲忋?/span>
渚嬪浜ゆ崲涓や釜鏁存暟a=10100001錛宐=00000110鐨勫鹼紝鍙氳繃涓嬪垪璇彞瀹炵幇錛?/span>
銆銆銆銆a = a^b錛?銆銆//a=10100111
銆銆銆銆b = b^a錛?銆銆//b=10100001
銆銆銆銆a = a^b錛?銆銆//a=00000110
(3) 鍦ㄦ眹緙栬璦涓粡甯哥敤浜庡皢鍙橀噺緗浂錛?/span>
xor a錛宎
(4) 蹇熷垽鏂袱涓兼槸鍚︾浉絳?/span>
涓句緥1: 鍒ゆ柇涓や釜鏁存暟a錛宐鏄惁鐩哥瓑錛屽垯鍙氳繃涓嬪垪璇彞瀹炵幇錛?/span>
return ((a ^ b) == 0)
涓句緥2: Linux涓渶鍒濈殑ipv6_addr_equal()鍑芥暟鐨勫疄鐜板涓?
static inline int ipv6_addr_equal(const struct in6_addr *a1, const struct in6_addr *a2)
{
return (a1->s6_addr32[0] == a2->s6_addr32[0] &&
a1->s6_addr32[1] == a2->s6_addr32[1] &&
a1->s6_addr32[2] == a2->s6_addr32[2] &&
a1->s6_addr32[3] == a2->s6_addr32[3]);
}
鍙互鍒╃敤鎸変綅寮傛垨瀹炵幇蹇熸瘮杈? 鏈鏂扮殑瀹炵幇宸茬粡淇敼涓?
static inline int ipv6_addr_equal(const struct in6_addr *a1, const struct in6_addr *a2)
{
return (((a1->s6_addr32[0] ^ a2->s6_addr32[0]) |
(a1->s6_addr32[1] ^ a2->s6_addr32[1]) |
(a1->s6_addr32[2] ^ a2->s6_addr32[2]) |
(a1->s6_addr32[3] ^ a2->s6_addr32[3])) == 0);
}
]]>
姹傛硶錛?/span>
/ if (sum[m-1] + T[m] >= 0){ sum[m] = sum[m -1] + T[m]}
sum[m] =
\else {sum[m] = T[m]}
sum[m]鏄埌涓嬫爣涓簃鐨勫厓绱犱負姝㈢殑鏈澶у瓙孌靛拰銆?br>
姹傚嚭sum[m]鍚庯紝綰挎壂鏁扮粍sum鐨勬渶澶у煎氨鏄墍姹傘?/span>
int sum;
void MaxSum(int n)

{
int i, b = 0;
for (i = 0; i < n; i++)
{
if (b >= 0)
{
b += T[i];
}
else
{
b = T[i];
}
if (sum < b)
{
sum = b;
}
}
}
]]>
x鐨勫鉤鏂癸細x*x鎴杧^2鎴杁ouble pow(x,y)(璁$畻x鐨剏鏂癸紝濡俻ow(x,2))
鎵浠ワ細
f(x)=x^2-1/exp(x)
欏轟究緇欏嚭C涓殑math.h涓殑鍑芥暟錛氫粎渚涘弬鑰?br>C璇█涓殑鏁板鍑芥暟(maths.h)
acos
double acos(x)
double x;
璁$畻arccos(x)鐨勫?
璁$畻緇撴灉
x搴斿湪-1鍒?鑼冨洿鍐?
asin
double asin(x)
double x;
璁$畻arcsin鐨勫?
璁$畻緇撴灉
x搴斿湪-1鍒?鑼冨洿鍐?
atan
double atan(x)
double x;
璁$畻arctan(x)鐨勫?
璁$畻緇撴灉
atan2
double atan2(x,y)
double x,y;
璁$畻arctan(x/y)鐨勫?
璁$畻緇撴灉
cos
double cos(x)
double x;
璁$畻cos(x)鐨勫?
璁$畻緇撴灉
x鐨勫崟浣嶄負寮у害
cosh
double cosh(x)
double x;
璁$畻x鐨勫弻鏇蹭綑寮osh(x)鐨勫?
璁$畻緇撴灉
exp
double exp(x)
double x;
姹俥鐨剎嬈℃柟騫?
璁$畻緇撴灉
fabs
double fabs(x)
double x;
姹?x鐨勭粷瀵瑰?
璁$畻緇撴灉
floor
double floor(x)
double x;
姹備笉澶т簬x鐨勬渶澶ф暣鏁?
璇ユ暣鏁扮殑鍙岀簿搴﹀疄鏁?
fmod
double fmod(x,y)
double x,y;
姹傛暣闄/y鐨勪綑鏁?
榪斿洖浣欐暟鐨勫弻綺懼害鏁?
frexp
double frexp(val,eptr)
double val;
int *eptr ;
鎶婂弻綺懼害鏁皏al鍒嗚В涓烘暟瀛楅儴鍒?灝炬暟)x鍜屼互2涓哄簳鐨勬寚鏁皀,鍗硋al=x*(2鐨?n嬈℃柟),瀛樻斁鍦╡ptr鎸囧悜鐨勫彉閲忎腑.
榪斿洖鏁板瓧閮ㄥ垎x
0.5x<1
log
double log(x)
double x;
姹俵nx
璁$畻緇撴灉
log10
double log10(x)
double x;
姹備互10涓哄簳x鐨勫鏁?
璁$畻緇撴灉
modf
double modf(val,iptr)
double val;
double iptr;
鎶婂弻綺懼害鏁皏al鍒嗚В涓烘暣鏁伴儴鍒嗗拰灝忔暟閮ㄥ垎,鎶婃暣鏁伴儴鍒嗗瓨鍒癷ptr鎸囧悜鐨勫崟鍏?
val鐨勫皬鏁伴儴鍒?
pow
double pow(x,y)
double x,y;
璁$畻x鐨剏嬈″箓
璁$畻緇撴灉
sin
double sin(x)
double x;
璁$畻sinx鐨勫?
璁$畻緇撴灉
x鐨勫崟浣嶄負寮у害
sinh
double sinh(x)
double x;
璁$畻x鐨勫弻鏇叉寮﹀嚱鏁皊inh(x)鐨勫?
璁$畻緇撴灉
sqrt
double sqrt(x)
double x;
璁$畻x鐨勫鉤鏂規牴
璁$畻緇撴灉
x搴斿ぇ浜庢垨絳変簬0
tan
double tan(x)
double x;
璁$畻tan(x)鐨勫?
璁$畻緇撴灉
x鍗曚綅涓哄害
tanh
double tanh(x)
double x;
璁$畻x鐨勫弻鏇叉鍒囧嚱鏁皌anh(x)鐨勫?
璁$畻緇撴灉
]]>
#include<stdio.h>
typedef int elemtype;
void Part(elemtype r[], int low, int high, int *pivotloc);
void QuickSort(elemtype r[], int low, int high);
int main()

{
int i, m;
elemtype r[1000];
while (1)
{
scanf("%d", &m);
for (i = 0; i < m; i++)
{
scanf("%d", &r[i]);
}
QuickSort(r, 0, m - 1);
printf("\n鎺掑簭緇撴灉-------------------------\n");
for (i = 0; i < m; i++)
{
printf("%d ", r[i]);
}
}
system("pause");
return 0;
}
void Part(elemtype r[], int low, int high, int *pivotloc)

{
int j, l = low, h = high;
elemtype pivotkey = r[low];//紜畾姣旇緝鍩烘暟
while (high != low)
{
while (low < high && pivotkey <= r[high])//鏌ユ壘r[low]鍙寵竟灝忎簬pivotkey鐨勫厓绱爎[high] 
{
high--;
}
if (low < high)
{
r[low] = r[high];
low++;
}
while (low < high && r[low] <= pivotkey)//鏌ユ壘r[high]宸﹁竟澶т簬pivotkey鐨勫厓绱爎[low] 
{
low++;
}
if (low < high)
{
r[high] = r[low];
high--;
}
}
r[high] = pivotkey;//灝嗘瘮杈冨熀鏁皃ivotkey璧嬬粰鍒嗙晫鐐?nbsp;
*pivotloc = high;//鏍囪鍒嗙晫鐐?nbsp;
for (j = l; j <= h; j++)
{
if (j == low)
{
printf("<%d> ", r[j]);//鎵撳嵃鍒嗙晫鐐圭殑鍊? r[l]鍒皉[low-1]鐨勬墍鏈夊厓绱犻兘灝忎簬鍒嗙晫鐐? r[low+1]鍒皉[h]寰楁墍鏈夊厓绱犻兘澶т簬鍒嗙晫鐐?nbsp;
}
else
{
printf("%d ", r[j]);
}
}
printf("\n");
}
void QuickSort(elemtype r[], int low, int high)

{
int i, j;
if (low < high)
{
Part(r, low, high, &i);
//鍥犱負Part鍑芥暟錛屼嬌r[low]鍒皉[i-1]鐨勬墍鏈夊厓绱犻兘灝忎簬r[i], r[i+1]鍒皉[high]寰楁墍鏈夊厓绱犻兘澶т簬r[i]錛屾墍浠ヤ笉闇瑕佸湪灝唕[i]鍙備笌鎺掑簭
QuickSort(r, low, i - 1);
QuickSort(r, i + 1, high);
}
}
/**//*
10
9 11 4 5 21 17 15 13 11 4
*/
]]>
#include<stdio.h>
typedef int elemtype;
void Adjust(elemtype r[], int k, int n);
void HeapSort(elemtype r[], int n);
int main()

{
int i, m;
elemtype r[1000];
while (1)
{
scanf("%d", &m);
if (m == 0)
{
break;
}
for (i = 1; i <= m; i++)
{
scanf("%d", &r[i]);
}
HeapSort(r, m);
}
system("pause");
return 0;
}
void Adjust(elemtype r[], int k, int n)//榪欓噷瀵規暟緇勮繘琛屽崌搴忔帓搴?nbsp;

{
int i, j;
elemtype tmp;
tmp = r[k];
i = k;
while (i * 2 <= n)//鍦ㄦ湁瀛╁瓙鐨勬儏鍐典笅閬嶅巻瀛╁瓙銆倀mp鏄綋鍓嶇粨鐐瑰鹼紝瀹冧繚鎸佷笉鍙?nbsp;
{
j = 2 * i;
if (j + 1 <= n && r[j+1] > r[j])//鎵懼嚭宸﹀彸瀛╁瓙涓殑杈冨ぇ鑰卌hildLarger 
{
j++;
}
if (tmp < r[j])
{
r[i] = r[j];//濡傛灉緇撶偣姣攃hildLarger灝忥紝灝嗗瀛愪笂縐誨埌緇撶偣
i = j;//灝嗕笅鏍囩Щ鎸囧悜childLarger鐨勪綅緗?nbsp;
}
else
{
break;//琛ㄦ槑i鎸囧悜鐨勭粨鐐圭殑瀛╁瓙閮芥瘮tmp灝?nbsp;
}
}
r[i] = tmp;
}
void HeapSort(elemtype r[], int n)

{
int i, j;
elemtype tmp;
for (i = n / 2; i >= 1; i--)//鎶婃爲璋冩暣鎴愬ぇ欏跺爢 
{
Adjust(r, i, n);
}
printf("\n\n澶ч《鍫?===========================\n");
for (j = 1; j <= n; j++)
{
printf("%d ", r[j]);
}
printf("===================================\n");
for (i = n; i >= 2; i--)
{
tmp = r[i];
r[i] = r[1];
r[1] = tmp;
Adjust(r, 1, i - 1);//i - 1鐩殑鏄笉璁〢djust鎶奿涓婄Щ錛屽洜涓簉[i]鏄痳[1]鍒皉[i]涓殑鏈澶у?nbsp;
printf("\n-------------------------------------\n");
for (j = 1; j <= n; j++)
{
printf("%d ", r[j]);
}
}
}

/**//*
11
1 3 2 5 11 7 4 13 19 6 9
*/
]]>
#include<stdio.h>
#include<stdlib.h>
#define MAX 500001
int array[MAX], array1[MAX];
__int64 sum;
void MergeSort(int, int);
void Merge(int, int, int);
int main()

{
int n, m, i, j = 0;
while (1)
{
sum = 0;
scanf("%d", &m);
if (m == 0)
{
break;
}
for (i = 0; i < m; i++)
{
scanf("%d", &array[i]);
}
MergeSort(0, m - 1);
printf("鎺掑簭緇撴灉\n");
for (i = 0; i < m; i++)
{
printf("%d\t", array[i]);
}
}
system("pause");
return 0;
}
void MergeSort(int i, int j)

{
int h;
if (i < j)
{
/**//* 灝嗛暱搴︿負m鐨勮緭鍏ュ簭鍒楀垎鎴愪袱涓暱搴︿負n/2鐨勫瓙搴忓垪 */
h = (i + j)/2;
printf("i = %d h = %d j = %d\n", i, h, j);
/**//* 瀵逛袱涓瓙搴忓垪鍒嗗埆榪涜褰掑茍鎺掑簭 */
MergeSort(i, h);
MergeSort(h + 1, j);
/**//* 灝?涓帓濂界殑瀛愬簭鍒楀悎騫舵垚鏈緇堟湁搴忓簭鍒?nbsp;*/
Merge(i, h, j);
}
}
void Merge(int i, int h, int j)

{
int k = 0, y = h + 1, x = i;
/**//* 2涓緭鍏ュ尯闂撮兘涓嶄負絀烘椂 */
while (x <= h && y <= j)
{
/**//* 鍙栧叧閿瓧灝忕殑璁板綍杞Щ鑷寵緭鍑哄尯闂?nbsp;*/
if (array[x] > array[y])
{
array1[k++] = array[y++];
sum += h - x + 1;
}
else
{
array1[k++] = array[x++];
}
}
/**//* 灝嗛潪絀虹殑杈撳叆鍖洪棿杞Щ鑷寵緭鍑哄尯闂?nbsp;*/
while (x <= h)
{
array1[k++] = array[x++];
}
while (y <= j)
{
array1[k++] = array[y++];
}
/**//* 褰掑茍瀹屾垚鍚庡皢緇撴灉澶嶅埗鍒板師杈撳叆鏁扮粍 */
printf("褰撳墠緇撴灉\n");
for(x = 0; x < k; x++)
{
array[i + x] = array1[x];
printf("%d ", array[i + x]);
}
printf("\n");
}
/**//*
6
1 2 5 6 3 4
*/
]]>
鍑芥暟鍘熷瀷錛?/p>
void qsort ( void * base, size_t num, size_t size, int ( * comparator ) ( const void *, const void * ) );
鐢ㄦ硶浠ュ強鍙傛暟璇存槑錛?/p>
base 鈥斺旇鎺掑簭鐨勬暟緇勮搗濮嬪湴鍧錛堟暟緇勫悕錛?br>num 鈥斺旀暟緇勫厓绱犱釜鏁?br>size 鈥斺旀暟緇勬瘡涓涓厓绱犵殑澶у皬
comparator 鈥斺斿嚱鏁版寚閽堬紝鎸囧悜姣旇緝鍑芥暟錛堟瘮杈冭鍒欙級
typedef struct

{
char p1[11];
char p2[11];
}T;
T str[size];
int q_cmp(const void *a, const void *b)

{
return strcmp(((T*)a)->p2, ((T*)b)->p2);
}
………………
………………
………………
qsort(str, i, sizeof(T), q_cmp);涓銆佸int綾誨瀷鏁扮粍鎺掑簭
int num[100];
int cmp ( const void *a , const void *b )
{
return *(int *)a - *(int *)b;//*(int *)a琛ㄧずa鎵鎸囧悜鐨勫湴鍧鐨勫唴瀹?br>}
qsort(num,100,sizeof(num[0]),cmp);
浜屻佸char綾誨瀷鏁扮粍鎺掑簭錛堝悓int綾誨瀷錛?/p>
char word[100];
int cmp( const void *a , const void *b )
{
return *(char *)a - *(int *)b;
}
qsort(word,100,sizeof(word[0]),cmp);
涓夈佸double綾誨瀷鏁扮粍鎺掑簭
double in[100];
int cmp( const void *a , const void *b )
{
return *(double *)a > *(double *)b ? 1 : -1;//鍙岀簿搴︽垨楂樼簿搴︾殑鏈濂界敤姣旇緝絎﹀彿姣旇緝澶у皬錛岄伩鍏嶇簿搴﹁宸殑閿欒
qsort(in,100,sizeof(in[0]),cmp);
鍥涖佸緇撴瀯浣撲竴綰ф帓搴?/p>
struct Sample
{
double data;
int other;
}s[100]
//鎸夌収data鐨勫間粠灝忓埌澶у皢緇撴瀯浣撴帓搴?/span>
int cmp( const void *a ,const void *b)
{
return (*(Sample *)a).data > (*(Sample *)b).data ? 1 : -1;
}
qsort(s,100,sizeof(s[0]),cmp);
浜斻佸緇撴瀯浣撲簩綰ф帓搴?/p>
struct Sample
{
int x;
int y;
}s[100];
//鎸夌収x浠庡皬鍒板ぇ鎺掑簭錛屽綋x鐩哥瓑鏃舵寜鐓浠庡ぇ鍒板皬鎺掑簭
int cmp( const void *a , const void *b )
{
struct Sample *c = (Sample *)a;
struct Sample *d = (Sample *)b;
if(c->x != d->x) return c->x - d->x;
else return d->y - c->y;
}
qsort(s,100,sizeof(s[0]),cmp);
鍏佸瀛楃涓茶繘琛屾帓搴?/p>
struct Sample
{
int data;
char str[100];
}s[100];
//鎸夌収緇撴瀯浣撲腑瀛楃涓瞫tr鐨勫瓧鍏擱『搴忔帓搴?/span>
int cmp ( const void *a , const void *b )
{
return strcmp( (*(Sample *)a)->str , (*(Sample *)b)->str );
}
qsort(s,100,sizeof(s[0]),cmp);
闄勫姞涓涓畬鏁寸偣鐨勪唬鐮侊紝瀵瑰瓧絎︿覆浜岀淮鏁扮粍鎺掑簭錛?/span>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
char s[2001][1001];
int cmp(const void *a, const void *b){
return strcmp((char *)a,(char *)b);
}
int main(){
int i,n;
scanf("%d",&n);
getchar();
for(i=0;i<n;i++) gets(s[i]);
qsort(s,n,1001*sizeof(char),cmp);
for(i=0;i<n;i++) puts(s[i]);
return 0;
}
寮曠敤浜巗lyar
void *bsearch(const void *key, const void *base, size_t num, size_t size, int (*cmp)(const void *, const void *));
key鈥斺?/strong> 鎸囧悜瑕佹煡鎵劇殑鍏冪礌
base鈥斺?/strong> 鎸囧悜榪涜鏌ユ壘鐨勬暟緇?/p>
num 鈥斺旀暟緇勪腑鍏冪礌鐨勪釜鏁?/p>
size鈥斺?/strong> 鏁扮粍涓瘡涓厓绱犵殑澶у皬錛屼竴鑸敤sizeof( T )琛ㄧず錛孴涓鑸槸鏁扮粍鐨勫厓绱犵被鍨?/p>
cmp 鈥斺旀瘮杈冧袱涓厓绱犵殑鍑芥暟錛屽畾涔夋瘮杈冭鍒欍傞渶瑕佹敞鎰忕殑鏄紝鏌ユ壘鏁扮粍蹇呴』鏄粡榪囬鍏堟帓搴忕殑錛岃屾帓搴忕殑瑙勫垯瑕佸拰姣旇緝瀛愬嚱鏁癱mp鐨勮鍒欑浉鍚屻?br>
姣斿錛?br>
typedef struct

{
char p1[11];
char p2[11];
}T;
T str[size];
int b_cmp(const void *a, const void* b)//瀹氫箟(b_cmp)鍙互闅忎究鏀?/span>

{
return strcmp((char*)a, ((T*)b)->p2);
}
char s[10];
………………
………………
………………
T *ptr = (T*)bsearch(s, str, i, sizeof(T), b_cmp);
寮曠敤浜巗lyar
]]>
#include<stdio.h>
#define n 10
#define m n * 2 - 1
typedef struct

{
int weight;
int lchild, rchild, parent;
}HTNode;
typedef HTNode HuffmanTree[m];
HuffmanTree t;
void IniHuffumanTree(HuffmanTree t)//鍒濆鍖栨瘡涓厓绱?nbsp;

{
int i;
for (i = 0; i < m; i++)
{
t[i].weight = 0;
t[i].lchild = t[i].rchild = t[i].parent = -1;
}
}
void InputWeight(HuffmanTree t)//杈撳叆姣忎釜緇撶偣錛堟爲錛夌殑鏉冨?nbsp;

{
int i;
for (i = 0; i < n; i++)
{
scanf("%d", &t[i].weight);
}
}
void SelectMin(HuffmanTree t, int i, int *p1, int *p2)//鍦ㄦ.鏋椾腑鎵懼嚭涓や釜鏉冩渶灝忕殑鏍?nbsp;

{
int j;
int min1, min2;
min1 = min2 = -1;
for (j = 0; j <= i; j++)
{
if (t[j].parent == -1)//琛ㄧず鏃犲弻浜茬殑緇撶偣 
{
if (t[j].weight < min1 || min1 == -1)
{
if (min1 != -1)//鍥犱負t[j].weight < min1錛屽張min2 > min1錛屾晠灝唌in1鐨勭浉鍏蟲暟鎹祴緇檓in2 
{
*p2 = *p1;
min2 = min1;
}
*p1 = j;
min1 = t[j].weight;
}
else if (t[j].weight < min2 || min2 == -1) 
{
*p2 = j;
min2 = t[j].weight;
}
}
}
}
void CreateHuffmanTree(HuffmanTree t)//鍒涘緩鍝堝か鏇兼爲 

{
int i, p1, p2;
IniHuffumanTree(t);
InputWeight(t);
for (i = n; i < m; i++)
{
SelectMin(t, i - 1, &p1, &p2);
t[p1].parent = t[p2].parent = i;
t[i].lchild = p1;
t[i].rchild = p2;
t[i].weight = t[p1].weight + t[p2].weight;
}
}
void Preorder(HuffmanTree t, int j)//瀵瑰搱澶浖鏍戠殑鍓嶅簭閬嶅巻 

{
int i = -1, h, stack[50];
stack[++i] = h = j;
while (h != -1)
{
h = stack[i--];
printf("%d ", t[h].weight);
if (t[h].rchild != -1)
{
stack[++i] = t[h].rchild;
}
if (t[h].lchild != -1)
{
stack[++i] = t[h].lchild;
}
if (i == -1)
{
return;
}
}
} 
int main()

{
int i;
CreateHuffmanTree(t);
for (i = 0; i < m; i++)
{
printf("%d ", t[i].weight);
}
printf("\n");
Preorder(t, m - 1);
system("pause");
return 0;
} 
/**//*嫻嬭瘯鏁版嵁
1 2 3 4 5 6 7 8 9 10