锘??xml version="1.0" encoding="utf-8" standalone="yes"?>久久91精品国产91久,国产精品福利一区二区久久,亚洲国产精品一区二区久久hshttp://www.shnenglu.com/zjj2816/category/2051.htmlzh-cnTue, 20 May 2008 18:49:16 GMTTue, 20 May 2008 18:49:16 GMT60qsort鍑芥暟搴旂敤澶у叏 涓冪qsort鎺掑簭鏂規(guī)硶 http://www.shnenglu.com/zjj2816/archive/2006/08/29/11816.html浜曟硥浜曟硥Tue, 29 Aug 2006 03:58:00 GMThttp://www.shnenglu.com/zjj2816/archive/2006/08/29/11816.htmlhttp://www.shnenglu.com/zjj2816/comments/11816.htmlhttp://www.shnenglu.com/zjj2816/archive/2006/08/29/11816.html#Feedback0http://www.shnenglu.com/zjj2816/comments/commentRss/11816.htmlhttp://www.shnenglu.com/zjj2816/services/trackbacks/11816.html
涓銆佸int綾誨瀷鏁扮粍鎺掑簭

int num[100];

Sample:

int cmp ( const void *a , const void *b )
{
return *(int *)a - *(int *)b;
}

qsort(num,100,sizeof(num[0]),cmp);

浜屻佸char綾誨瀷鏁扮粍鎺掑簭錛堝悓int綾誨瀷錛?

char word[100];

Sample:

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)錛?

鍥涖佸緇撴瀯浣撲竴綰ф帓搴?

struct In
{
double data;
int other;
}s[100]

//鎸夌収data鐨勫間粠灝忓埌澶у皢緇撴瀯浣撴帓搴?鍏充簬緇撴瀯浣撳唴鐨勬帓搴忓叧閿暟鎹甦ata鐨勭被鍨嬪彲浠ュ緢澶氱錛屽弬鑰冧笂闈㈢殑渚嬪瓙鍐?

int cmp( const void *a ,const void *B)
{
return (*(In *)a)->data > (*(In *)B)->data ? 1 : -1;
}

qsort(s,100,sizeof(s[0]),cmp);

浜斻佸緇撴瀯浣撲簩綰ф帓搴?

struct In
{
int x;
int y;
}s[100];

//鎸夌収x浠庡皬鍒板ぇ鎺掑簭錛屽綋x鐩哥瓑鏃舵寜鐓浠庡ぇ鍒板皬鎺掑簭

int cmp( const void *a , const void *b )
{
struct In *c = (In *)a;
struct In *d = (In *)b;
if(c->x != d->x) return c->x - d->x;
else return d->y - c->y;
}

qsort(s,100,sizeof(s[0]),cmp);

鍏佸瀛楃涓茶繘琛屾帓搴?

struct In
{
int data;
char str[100];
}s[100];

//鎸夌収緇撴瀯浣撲腑瀛楃涓瞫tr鐨勫瓧鍏擱『搴忔帓搴?

int cmp ( const void *a , const void *b )
{
return strcmp( (*(In *)a)->str , (*(In *)B)->str );
}

qsort(s,100,sizeof(s[0]),cmp);

涓冦佽綆楀嚑浣曚腑姹傚嚫鍖呯殑cmp

int cmp(const void *a,const void *B) //閲嶇偣cmp鍑芥暟錛屾妸闄や簡1鐐瑰鐨勬墍鏈夌偣錛屾棆杞搴︽帓搴?
{
struct point *c=(point *)a;
struct point *d=(point *)b;
if( calc(*c,*d,p[1]) < 0) return 1;
else if( !calc(*c,*d,p[1]) && dis(c->x,c->y,p[1].x,p[1].y) < dis(d->x,d->y,p[1].x,p[1].y)) //濡傛灉鍦ㄤ竴鏉$洿綰夸笂錛屽垯鎶婅繙鐨勬斁鍦ㄥ墠闈?
return 1;
else return -1;
}

PS:

鍏朵腑鐨剄sort鍑芥暟鍖呭惈鍦?lt;stdlib.h>鐨勫ご鏂囦歡閲岋紝strcmp鍖呭惈鍦?lt;string.h>鐨勫ご鏂囦歡閲?img src ="http://www.shnenglu.com/zjj2816/aggbug/11816.html" width = "1" height = "1" />

浜曟硥 2006-08-29 11:58 鍙戣〃璇勮
]]>
鍦?C/C++ 涓浣曟瀯閫犻氱敤鐨勫璞¢摼琛?/title><link>http://www.shnenglu.com/zjj2816/archive/2006/06/26/9034.html</link><dc:creator>浜曟硥</dc:creator><author>浜曟硥</author><pubDate>Mon, 26 Jun 2006 11:37:00 GMT</pubDate><guid>http://www.shnenglu.com/zjj2816/archive/2006/06/26/9034.html</guid><wfw:comment>http://www.shnenglu.com/zjj2816/comments/9034.html</wfw:comment><comments>http://www.shnenglu.com/zjj2816/archive/2006/06/26/9034.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.shnenglu.com/zjj2816/comments/commentRss/9034.html</wfw:commentRss><trackback:ping>http://www.shnenglu.com/zjj2816/services/trackbacks/9034.html</trackback:ping><description><![CDATA[涓涓畝鍖栫殑闂紺轟緥<br /><br />閾捐〃鐨勯毦鐐瑰湪浜庡繀欏誨鍒墮摼琛ㄥ鐞嗗嚱鏁版潵澶勭悊涓嶅悓鐨勫璞★紝鍗充究閫昏緫鏄畬鍏ㄧ浉鍚岀殑銆備緥濡備袱涓粨鏋勭被浼肩殑閾捐〃:<br /><br /><br /><center><ccid_nobr><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="black" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code>struct Struct_Object_A 銆銆{ 銆銆銆銆int a; 銆銆銆銆int b; 銆銆銆銆Struct_Object_A *next; 銆銆 銆銆} OBJECT_A; 銆銆 銆銆typedef struct Struct_Object_B 銆銆{ 銆銆銆銆int a; 銆銆銆銆int b; 銆銆銆銆int c; 銆銆銆銆Struct_Object_B *next; 銆銆 銆銆} OBJECT_B;銆</ccid_code></pre></td></tr></tbody></table></ccid_nobr></center><p style="TEXT-INDENT: 2em">涓婇潰瀹氫箟鐨勪袱涓粨鏋勫彧鏈夊緢灝忕殑涓鐐瑰樊鍒侽BJECT_B 鍜?OBJECT_A 涔嬮棿鍙樊涓涓暣鍨嬪彉閲忋備絾鏄紝鍦ㄧ紪璇戝櫒鐪嬫潵錛屽畠浠粛鐒舵槸闈炲父涓嶅悓鐨勩傚繀欏諱負(fù)瀛樺偍鍦ㄩ摼琛ㄤ腑鐨勬瘡涓璞″鍒剁敤鏉ユ坊鍔犮佸垹闄ゅ拰鎼滅儲閾捐〃鐨勫嚱鏁般備負(fù)浜嗚В鍐寵繖涓棶棰橈紝鍙互浣跨敤鍏鋒湁鍏ㄩ儴涓変釜鍙橀噺鐨勪竴涓仈鍚堟垨緇撴瀯錛屽叾涓暣鏁?c 騫朵笉鏄湪鎵鏈夌殑鎯呭喌涓嬮兘瑕佷嬌鐢ㄣ傝繖鍙兘鍙樺緱闈炲父澶嶆潅錛屽茍浼?xì)迮炴垚涓嶈壇鐨劸~栫▼椋庢牸銆? </p><p style="TEXT-INDENT: 2em">C 浠g爜瑙e喅鏂規(guī)錛氳櫄鎷熼摼琛? </p><p style="TEXT-INDENT: 2em">姝ら棶棰樻洿濂界殑瑙e喅鏂規(guī)涔嬩竴鏄櫄鎷熼摼琛ㄣ傝櫄鎷熼摼琛ㄦ槸鍙寘鍚摼琛ㄦ寚閽堢殑閾捐〃銆傚璞″瓨鍌ㄥ湪閾捐〃緇撴瀯鑳屽悗銆傝繖涓鐐規(guī)槸榪欐牱瀹炵幇鐨勶紝棣栧厛涓洪摼琛ㄨ妭鐐瑰垎閰嶅唴瀛橈紝鎺ョ潃涓哄璞″垎閰嶅唴瀛橈紝鐒跺悗灝嗚繖鍧楀唴瀛樺垎閰嶇粰閾捐〃鑺傜偣鎸囬拡錛屽涓嬫墍紺猴細(xì) </p><p style="TEXT-INDENT: 2em">铏氭嫙閾捐〃緇撴瀯鐨勪竴縐嶅疄鐜? </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="black" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code>typedef struct liststruct 銆銆{ 銆銆銆銆liststruct *next; 銆銆 銆銆} LIST, *pLIST; 銆銆 銆銆pLIST Head = NULL; 銆銆 銆銆pLIST AddToList( pLIST Head, void * data, size_t datasize ) 銆銆{ 銆銆pLIST newlist=NULL; 銆銆void *p; 銆銆 銆銆銆銆// 鍒嗛厤鑺傜偣鍐呭瓨鍜屾暟鎹唴瀛? 銆銆銆銆newlist = (pLIST) malloc ( datasize + sizeof( LIST ) ); 銆銆 銆銆銆銆// 涓鴻繖鍧楁暟鎹紦鍐插尯鎸囧畾涓涓寚閽? 銆銆銆銆p = (void *)( newlist + 1 ); 銆銆 銆銆銆銆// 澶嶅埗鏁版嵁 銆銆銆銆memcpy( p, data, datasize ); 銆銆 銆銆銆銆// 灝嗚繖涓妭鐐規(guī)寚瀹氱粰閾捐〃鐨勮〃澶? 銆銆銆銆if( Head ) 銆銆銆銆{ 銆銆銆銆newlist->next = Head; 銆銆銆銆} 銆銆銆銆else 銆銆銆銆newlist->next = NULL; 銆銆 銆銆銆銆Head = newlist; 銆銆 銆銆銆銆return Head; 銆銆}銆銆</ccid_code></pre></td></tr></tbody></table></ccid_nobr></center><p style="TEXT-INDENT: 2em">閾捐〃鑺傜偣鐜板湪寤虹珛鍦ㄦ暟鎹煎壇鏈殑鍩烘湰涔嬩笂銆傝繖涓増鏈兘寰堝ソ鍦板鐞嗘爣閲忓鹼紝浣嗕笉鑳藉鐞嗗甫鏈夌敤 malloc 鎴?new 鍒嗛厤鐨勫厓绱犵殑瀵硅薄銆傝澶勭悊榪欎簺瀵硅薄錛孡IST 緇撴瀯闇瑕佸寘鍚竴涓竴鑸殑瑙i櫎鍑芥暟鎸囬拡錛岃繖涓寚閽堝彲鐢ㄦ潵鍦ㄥ皢鑺傜偣浠庨摼琛ㄤ腑鍒犻櫎騫惰В闄ゅ畠涔嬪墠閲婃斁鍐呭瓨錛堟垨鑰呭叧闂枃浠訛紝鎴栬呰皟鐢ㄥ叧闂柟娉曪級銆? </p><p style="TEXT-INDENT: 2em">涓涓甫鏈夎В闄ゅ嚱鏁扮殑閾捐〃 </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="black" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code>typedef void (*ListNodeDestructor)( void * ); 銆銆 銆銆typedef struct liststruct 銆銆{ 銆銆銆銆ListNodeDestructor DestructFunc; 銆銆銆銆liststruct *next; 銆銆 銆銆} LIST, *pLIST; 銆銆 銆銆pLIST AddToList( pLIST Head, void * data, size_t datasize, 銆銆ListNodeDestructor Destructor ) 銆銆{ 銆銆pLIST newlist=NULL; 銆銆void *p; 銆銆 銆銆 銆銆銆銆// 鍒嗛厤鑺傜偣鍐呭瓨鍜屾暟鎹唴瀛? 銆銆銆銆newlist = (pLIST) malloc ( datasize + sizeof( LIST ) ); 銆銆 銆銆銆銆// 涓鴻繖鍧楁暟鎹紦鍐插尯鎸囧畾涓涓寚閽? 銆銆銆銆p = (void *)( newlist + 1 ); 銆銆 銆銆銆銆// 澶嶅埗鏁版嵁 銆銆銆銆memcpy( p, data, datasize ); 銆銆 銆銆銆銆newlist->DestructFunc = Destructor; 銆銆銆銆 銆銆銆銆// 灝嗚繖涓妭鐐規(guī)寚瀹氱粰閾捐〃鐨勮〃澶? 銆銆銆銆if( Head ) 銆銆銆銆{ 銆銆銆銆銆銆newlist->next = Head; 銆銆銆銆} 銆銆銆銆else 銆銆銆銆銆銆newlist->next = NULL; 銆銆 銆銆銆銆Head = newlist; 銆銆 銆銆銆銆return Head; 銆銆} 銆銆 銆銆void DeleteList( pLIST Head ) 銆銆{ 銆銆銆銆pLIST Next; 銆銆銆銆while( Head ) 銆銆銆銆{ 銆銆銆銆銆銆Next = Head->next; 銆銆銆銆銆銆Head->DestructFunc( (void *) Head ); 銆銆銆銆銆銆free( Head ); 銆銆銆銆銆銆Head = Next; 銆銆銆銆} 銆銆} 銆銆 銆銆typedef struct ListDataStruct 銆銆{ 銆銆銆銆LPSTR p; 銆銆 銆銆} LIST_DATA, *pLIST_DATA; 銆銆 銆銆void ListDataDestructor( void *p ) 銆銆{ 銆銆銆銆// 瀵硅妭鐐規(guī)寚閽堣繘琛岀被鍨嬭漿鎹? 銆銆銆銆pLIST pl = (pLIST)p; 銆銆 銆銆銆銆// 瀵規(guī)暟鎹寚閽堣繘琛岀被鍨嬭漿鎹? 銆銆銆銆pLIST_DATA pLD = (pLIST_DATA) ( pl + 1 ); 銆銆 銆銆銆銆delete pLD->p; 銆銆} 銆銆pLIST Head = NULL; 銆銆 銆銆void TestList() 銆銆{ 銆銆銆銆pLIST_DATA d = new LIST_DATA; 銆銆銆銆d->p = new char[24]; 銆銆銆銆strcpy( d->p, "Hello" ); 銆銆銆銆Head = AddToList( Head, (void *) d, sizeof( pLIST_DATA ), 銆銆銆銆ListDataDestructor ); 銆銆銆銆// 璇ュ璞″凡琚鍒訛紝鐜板湪鍒犻櫎鍘熸潵鐨勫璞? 銆銆銆銆delete d; 銆銆 銆銆銆銆d = new LIST_DATA; 銆銆銆銆d->p = new char[24]; 銆銆銆銆strcpy( d->p, "World" ); 銆銆銆銆Head = AddToList( Head, (void *) d, sizeof( pLIST_DATA ), 銆銆銆銆ListDataDestructor ); 銆銆銆銆delete d; 銆銆 銆銆銆銆// 閲婃斁閾捐〃 銆銆銆銆DeleteList( Head ); 銆銆}銆銆銆</ccid_code></pre></td></tr></tbody></table></ccid_nobr></center><p style="TEXT-INDENT: 2em">鍦ㄦ瘡涓摼琛ㄨ妭鐐逛腑鍖呭惈鍚屼竴涓В闄ゅ嚱鏁扮殑鍚屼竴涓寚閽堜技涔庢槸嫻垂鍐呭瓨絀洪棿銆傜‘瀹炲姝わ紝浣嗗彧鏈夐摼琛ㄥ緇堝寘鍚浉鍚岀殑瀵硅薄鎵嶅睘浜庤繖縐嶆儏鍐點(diǎn)傛寜榪欑鏂瑰紡緙栧啓閾捐〃鍏佽鎮(zhèn)ㄥ皢浠諱綍瀵硅薄鏀懼湪閾捐〃涓殑浠諱綍浣嶇疆銆傚ぇ澶氭暟閾捐〃鍑芥暟瑕佹眰瀵硅薄鎬繪槸鐩稿悓鐨勭被鍨嬫垨綾匯? </p><p style="TEXT-INDENT: 2em">铏氭嫙閾捐〃鍒欐棤姝よ姹傘傚畠鎵闇瑕佺殑鍙槸灝嗗璞″郊姝ゅ尯鍒嗗紑鐨勪竴縐嶆柟娉曘傝瀹炵幇榪欎竴鐐癸紝鎮(zhèn)ㄦ棦鍙互媯嫻嬭В闄ゅ嚱鏁版寚閽堢殑鍊鹼紝涔熷彲浠ュ湪閾捐〃涓墍鐢ㄧ殑鍏ㄩ儴緇撴瀯鍓嶆坊鍔犱竴涓被鍨嬪煎茍瀵瑰畠榪涜媯嫻嬨? </p><p style="TEXT-INDENT: 2em">褰撶劧錛屽鏋滆灝嗛摼琛ㄧ紪鍐欎負(fù)涓涓?C++ 綾伙紝鍒欏鎸囧悜瑙i櫎鍑芥暟鐨勬寚閽堢殑璁劇疆鍜屽瓨鍌ㄥ彧鑳借繘琛屼竴嬈°? </p><p style="TEXT-INDENT: 2em">C++ 瑙e喅鏂規(guī)錛氱被閾捐〃 </p><p style="TEXT-INDENT: 2em">鏈В鍐蟲柟妗堝皢 CList 綾誨畾涔変負(fù)浠?LIST 緇撴瀯瀵煎嚭鐨勪竴涓被錛屽畠閫氳繃瀛樺偍瑙i櫎鍑芥暟鐨勫崟涓兼潵澶勭悊鍗曚釜瀛樺偍綾誨瀷銆傝娉ㄦ剰娣誨姞鐨?GetCurrentData() 鍑芥暟錛岃鍑芥暟瀹屾垚浠庨摼琛ㄨ妭鐐規(guī)寚閽堝埌鏁版嵁鍋忕Щ鎸囬拡鐨勬暟瀛﹁漿鎹€備竴涓櫄鎷熼摼琛ㄥ璞? </p><p style="TEXT-INDENT: 2em"></p><center><ccid_nobr><table cellspacing="0" bordercolordark="#ffffff" cellpadding="2" width="400" align="center" bordercolorlight="black" border="1"><tbody><tr><td class="code" style="FONT-SIZE: 9pt" bgcolor="#e6e6e6"><pre><ccid_code>// 瀹氫箟瑙i櫎鍑芥暟鎸囬拡 銆銆 銆銆typedef void (*ListNodeDestructor) ( void * ); 銆銆 銆銆// 鏈坊鍔犺В闄ゅ嚱鏁版寚閽堢殑閾捐〃 銆銆 銆銆typedef struct ndliststruct 銆銆{ 銆銆銆銆ndliststruct *next; 銆銆 銆銆} ND_LIST, *pND_LIST; 銆銆 銆銆// 瀹氫箟澶勭悊涓縐嶆暟鎹被鍨嬬殑閾捐〃綾? 銆銆 銆銆class CList : public ND_LIST 銆銆{ 銆銆public: 銆銆銆銆CList(ListNodeDestructor); 銆銆銆銆~CList(); 銆銆銆銆pND_LIST AddToList ( void * data, size_t datasize ); 銆銆銆銆void *GetCurrentData(); 銆銆銆銆void DeleteList( pND_LIST Head ); 銆銆 銆銆 銆銆private: 銆銆銆銆pND_LIST m_HeadOfList; 銆銆銆銆pND_LIST m_CurrentNode; 銆銆銆銆ListNodeDestructor m_DestructFunc; 銆銆}; 銆銆 銆銆// 鐢ㄦ紜殑璧峰鍊兼瀯閫犺繖涓摼琛ㄥ璞? 銆銆 銆銆CList::CList(ListNodeDestructor Destructor) 銆銆銆銆: m_HeadOfList(NULL), m_CurrentNode(NULL) 銆銆{ 銆銆銆銆m_DestructFunc = Destructor; 銆銆} 銆銆 銆銆// 鍦ㄨВ闄ゅ璞′互鍚庡垹闄ら摼琛? 銆銆 銆銆CList::~CList() 銆銆{ 銆銆銆銆DeleteList(m_HeadOfList); 銆銆} 銆銆 銆銆// 鍚戦摼琛ㄤ腑娣誨姞涓涓柊鑺傜偣 銆銆 銆銆pND_LIST CList::AddToList ( void * data, size_t datasize ) 銆銆{ 銆銆pND_LIST newlist=NULL; 銆銆void *p; 銆銆 銆銆 銆銆銆銆// 鍒嗛厤鑺傜偣鍐呭瓨鍜屾暟鎹唴瀛? 銆銆銆銆newlist = (pND_LIST) malloc ( datasize + sizeof( ND_LIST ) ); 銆銆 銆銆銆銆// 涓鴻繖鍧楁暟鎹紦鍐插尯鎸囧畾涓涓寚閽? 銆銆銆銆p = (void *)( newlist + 1 ); 銆銆 銆銆銆銆// 澶嶅埗鏁版嵁 銆銆銆銆memcpy( p, data, datasize ); 銆銆 銆銆銆銆// 灝嗚繖涓妭鐐規(guī)寚瀹氱粰閾捐〃鐨勮〃澶? 銆銆銆銆if( m_HeadOfList ) 銆銆銆銆{ 銆銆銆銆銆銆newlist->next = m_HeadOfList; 銆銆銆銆} 銆銆銆銆else 銆銆銆銆銆銆newlist->next = NULL; 銆銆 銆銆銆銆m_HeadOfList = newlist; 銆銆 銆銆銆銆return m_HeadOfList; 銆銆} 銆銆 銆銆// 灝嗗綋鍓嶇殑鑺傜偣鏁版嵁浣滀負(fù) void 綾誨瀷榪斿洖錛? 浠ヤ究璋冪敤鍑芥暟鑳藉灝嗗畠杞崲涓轟換浣曠被鍨? 銆銆 銆銆void * CList::GetCurrentData() 銆銆{ 銆銆銆銆return (void *)(m_CurrentNode+1); 銆銆} 銆銆 銆銆// 鍒犻櫎宸插垎閰嶇殑閾捐〃 銆銆 銆銆void CList::DeleteList( pND_LIST Head ) 銆銆{ 銆銆銆銆pND_LIST Next; 銆銆銆銆while( Head ) 銆銆銆銆{ 銆銆銆銆銆銆Next = Head->next; 銆銆銆銆銆銆m_DestructFunc( (void *) Head ); 銆銆銆銆銆銆free( Head ); 銆銆銆銆銆銆Head = Next; 銆銆銆銆} 銆銆} 銆銆 銆銆// 鍒涘緩涓涓鍦ㄩ摼琛ㄤ腑鍒涘緩鍜屽瓨鍌ㄧ殑緇撴瀯 銆銆 銆銆typedef struct ListDataStruct 銆銆{ 銆銆銆銆LPSTR p; 銆銆 銆銆} LIST_DATA, *pND_LIST_DATA; 銆銆 銆銆// 瀹氫箟鏍囧噯瑙i櫎鍑芥暟 銆銆 銆銆void ClassListDataDestructor( void *p ) 銆銆{ 銆銆銆銆// 瀵硅妭鐐規(guī)寚閽堣繘琛岀被鍨嬭漿鎹? 銆銆銆銆pND_LIST pl = (pND_LIST)p; 銆銆 銆銆銆銆// 瀵規(guī)暟鎹寚閽堣繘琛岀被鍨嬭漿鎹? 銆銆銆銆pND_LIST_DATA pLD = (pND_LIST_DATA) ( pl + 1 ); 銆銆 銆銆銆銆delete pLD->p; 銆銆} 銆銆 銆銆// 嫻嬭瘯涓婇潰鐨勪唬鐮? 銆銆 銆銆void MyCListClassTest() 銆銆{ 銆銆銆銆// 鍒涘緩閾捐〃綾? 銆銆 銆銆銆銆CList* pA_List_of_Data = new CList(ClassListDataDestructor); 銆銆 銆銆銆銆// 鍒涘緩鏁版嵁瀵硅薄 銆銆銆銆 銆銆銆銆pND_LIST_DATA d = new LIST_DATA; 銆銆銆銆d->p = new char[24]; 銆銆銆銆strcpy( d->p, "Hello" ); 銆銆 銆銆銆銆// 鍒涘緩鎸囧悜閾捐〃欏墮儴鐨勫眬閮ㄦ寚閽? 銆銆 銆銆銆銆pND_LIST Head = NULL; 銆銆 銆銆銆銆//鍚戦摼琛ㄤ腑娣誨姞涓浜涙暟鎹? 銆銆 銆銆銆銆Head = pA_List_of_Data->AddToList ( (void *) d, 銆銆銆銆sizeof( pND_LIST_DATA ) ); 銆銆銆銆// 璇ュ璞″凡琚鍒訛紝鐜板湪鍒犻櫎鍘熸潵鐨勫璞? 銆銆銆銆delete d; 銆銆 銆銆銆銆// 紜瀹冨凡琚瓨鍌? 銆銆銆銆char * p = ((pND_LIST_DATA) pA_List_of_Data->GetCurrentData())->p; 銆銆 銆銆銆銆d = new LIST_DATA; 銆銆銆銆d->p = new char[24]; 銆銆銆銆strcpy( d->p, "World" ); 銆銆銆銆Head = pA_List_of_Data->AddToList ( (void *) d, sizeof( pND_LIST_DATA ) ); 銆銆銆銆// 璇ュ璞″凡琚鍒訛紝鐜板湪鍒犻櫎鍘熸潵鐨勫璞? 銆銆銆銆delete d; 銆銆 銆銆銆銆// 紜瀹冨凡琚瓨鍌? 銆銆銆銆p = ((pND_LIST_DATA) pA_List_of_Data->GetCurrentData())->p; 銆銆 銆銆銆銆// 鍒犻櫎閾捐〃綾伙紝鏋愭瀯鍑芥暟灝嗗垹闄ら摼琛? 銆銆銆銆delete pA_List_of_Data; 銆銆}</ccid_code></pre></td></tr></tbody></table></ccid_nobr></center>銆銆 <p style="TEXT-INDENT: 2em">灝忕粨 </p><p style="TEXT-INDENT: 2em">浠庡墠闈㈢殑璁ㄨ鏉ョ湅錛屼技涔庝粎緙栧啓涓涓畝鍗曠殑閾捐〃灝辮鍋氬ぇ閲忕殑宸ヤ綔錛屼絾榪欏彧欏昏繘琛屼竴嬈°傚緢瀹規(guī)槗灝嗚繖孌典唬鐮佹墿鍏呬負(fù)涓涓鐞嗘帓搴忋佹悳绱互鍙?qiáng)鍚効U嶅叾浠栦換鍔$殑 C++ 綾伙紝騫朵笖榪欎釜綾誨彲浠ュ鐞嗕換浣曟暟鎹璞℃垨綾伙紙鍦ㄤ竴涓」鐩腑錛屽畠澶勭悊澶х害浜屽崄涓笉鍚岀殑瀵硅薄錛夈傛?zhèn)ㄦ案杩滀笉蹇呴噸鏂熬~栧啓榪欐浠g爜銆?/p><img src ="http://www.shnenglu.com/zjj2816/aggbug/9034.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.shnenglu.com/zjj2816/" target="_blank">浜曟硥</a> 2006-06-26 19:37 <a href="http://www.shnenglu.com/zjj2816/archive/2006/06/26/9034.html#Feedback" target="_blank" style="text-decoration:none;">鍙戣〃璇勮</a></div>]]></description></item><item><title>闃熷垪http://www.shnenglu.com/zjj2816/archive/2006/06/26/9033.html浜曟硥浜曟硥Mon, 26 Jun 2006 11:25:00 GMThttp://www.shnenglu.com/zjj2816/archive/2006/06/26/9033.htmlhttp://www.shnenglu.com/zjj2816/comments/9033.htmlhttp://www.shnenglu.com/zjj2816/archive/2006/06/26/9033.html#Feedback0http://www.shnenglu.com/zjj2816/comments/commentRss/9033.htmlhttp://www.shnenglu.com/zjj2816/services/trackbacks/9033.html 闃熷垪

闇瑕侀槦鍒楁槸鍑轟簬涓や釜鍘熷洜銆傞鍏堬紝闇瑕侀槦鍒楁潵淇濆瓨宸ヤ綔浣滀笟銆傝繕闇瑕佸彲鐢ㄤ簬璺熻釜宸茬粓姝㈢嚎紼嬬殑鏁版嵁緇撴瀯銆傝繕璁板緱鍓嶅嚑綃囨枃绔狅紙璇峰弬闃呮湰鏂囩粨灝懼鐨?鍙傝冭祫鏂?/font>錛変腑錛屾垜鏇炬彁鍒拌繃闇瑕佷嬌鐢ㄥ甫鏈夌壒瀹氳繘紼嬫爣璇嗙殑 pthread_join 鍚楋紵浣跨敤鈥滄竻闄ら槦鍒椻濓紙縐頒綔 "cq"錛夊彲浠ヨВ鍐蟲棤娉曠瓑寰?浠諱綍宸茬粓姝㈢嚎紼嬬殑闂錛堢◢鍚庡皢璇︾粏璁ㄨ榪欎釜闂錛夈備互涓嬫槸鏍囧噯闃熷垪浠g爜銆傚皢姝や唬鐮佷繚瀛樺埌鏂囦歡 queue.h 鍜?queue.c錛?


queue.h
												
														/* queue.h
** Copyright 2000 Daniel Robbins, Gentoo Technologies, Inc.
** Author: Daniel Robbins
** Date: 16 Jun 2000
*/

typedef struct node {
  struct node *next;
} node;

typedef struct queue {
  node *head, *tail; 
} queue;

void queue_init(queue *myroot);
void queue_put(queue *myroot, node *mynode);
node *queue_get(queue *myroot);

												
										



queue.c
												
														/* queue.c
** Copyright 2000 Daniel Robbins, Gentoo Technologies, Inc.
** Author: Daniel Robbins
** Date: 16 Jun 2000
**
** This set of queue functions was originally thread-aware.  I
** redesigned the code to make this set of queue routines
** thread-ignorant (just a generic, boring yet very fast set of queue
** routines).  Why the change?  Because it makes more sense to have
** the thread support as an optional add-on.  Consider a situation
** where you want to add 5 nodes to the queue.  With the
** thread-enabled version, each call to queue_put() would
** automatically lock and unlock the queue mutex 5 times -- that's a
** lot of unnecessary overhead.  However, by moving the thread stuff
** out of the queue routines, the caller can lock the mutex once at
** the beginning, then insert 5 items, and then unlock at the end.
** Moving the lock/unlock code out of the queue functions allows for
** optimizations that aren't possible otherwise.  It also makes this
** code useful for non-threaded applications.
**
** We can easily thread-enable this data structure by using the
** data_control type defined in control.c and control.h.  */

#include <stdio.h>
#include "queue.h"

void queue_init(queue *myroot) {
  myroot->head=NULL;
  myroot->tail=NULL;
}

void queue_put(queue *myroot,node *mynode) {
  mynode->next=NULL;
  if (myroot->tail!=NULL)
    myroot->tail->next=mynode;
  myroot->tail=mynode;
  if (myroot->:head==NULL)
    myroot->head=mynode;
}

node *queue_get(queue *myroot) {
  //get from root
  node *mynode;
  mynode=myroot->head;
  if (myroot->head!=NULL)
    myroot->head=myroot->head->next;
  return mynode;
}

												
										


浜曟硥 2006-06-26 19:25 鍙戣〃璇勮
]]>
一本色道久久99一综合| 97精品伊人久久久大香线蕉| 97r久久精品国产99国产精| 97久久精品午夜一区二区| 国产精品视频久久| 亚洲国产综合久久天堂| 精品少妇人妻av无码久久| 久久国产视频99电影| 久久精品国产免费观看| 久久中文字幕一区二区| 亚洲AV伊人久久青青草原| 婷婷伊人久久大香线蕉AV | 国产99久久久久久免费看| 亚洲国产日韩欧美综合久久| 午夜不卡久久精品无码免费| 久久综合狠狠色综合伊人| 一本色道久久综合亚洲精品| 欧美亚洲另类久久综合| 伊人久久大香线蕉亚洲五月天 | 亚洲国产精品无码久久久久久曰 | 国产午夜精品理论片久久影视 | 狠狠久久综合| 久久发布国产伦子伦精品| 亚洲第一永久AV网站久久精品男人的天堂AV| 国产aⅴ激情无码久久| 久久久WWW成人| 草草久久久无码国产专区| 97久久超碰成人精品网站| 久久99久国产麻精品66| 亚洲精品美女久久久久99小说| 久久亚洲高清观看| 久久国产乱子精品免费女| 久久久久亚洲AV无码永不| 久久天天躁狠狠躁夜夜2020| 久久99热狠狠色精品一区| 久久亚洲AV成人无码国产| 伊人久久大香线蕉av不卡| 99久久国产综合精品女同图片| 国内精品久久久久影院亚洲| 亚洲国产婷婷香蕉久久久久久| 91秦先生久久久久久久|