看板 PCSH91_305 關於我們 聯絡資訊
※ [本文轉錄自 nfsong 信箱] 作者: LiloHuang (築夢踏實) 看板: share 標題: [情報] BBS 程式碼標色小工具 時間: Sun Jun 10 22:58:14 2007 可針對 C, Java, PHP, Perl , Python, Bash, SQL, HTML, XML, CSS, Javascript 等... 程式碼做標色動作, 我則修改自Google Code Prettifier的版本, 改良為BBS標色工具 PS. 轉換後直接全選複製, 彩色貼上到BBS畫面即可 ( 注意, 這個工具不會自動修改寬度 ) http://blog.roodo.com/kenwu/archives/3444993.html 效果: [ 以非遞迴快速排序法為例 ] #include<iostream> #include<cstdlib> #include<stack> using namespace std; typedef struct stack_node *ptr; // 定義一個結構 裡面有low/high typedef struct stack_node { int low; int high; }; stack<ptr> s; // 定義一個堆疊, 使用上面結構 void quicksort(int list[],int first,int last) { ptr entry = new stack_node; entry->low = first; entry->high = last; s.push(entry); // 產生一個新節點 紀錄邊界值 while( !s.empty() ) // 當堆疊非空, 進行切割征服 { ptr temp = s.top(); // 取出堆疊頂端 s.pop(); // pop刪除堆疊頂端 if(temp->low < temp->high) // 如果要排的資料陣列位置正確 { int key = list[temp->low]; int left = temp->low; int right = temp->high+1; do { do left++; while(list[left]<key); do right--; while(list[right]>key); if(left<right) { swap(list[left],list[right]); } } while (left<right); swap(list[temp->low],list[right]); // 與中間值交換 ptr leftrec = new stack_node; // 產生模擬左遞迴的堆疊節點 leftrec->low = temp->low; leftrec->high = right-1; ptr rightrec = new stack_node; // 產生模擬右遞迴的堆疊節點 rightrec->low = right+1; rightrec->high = temp->high; s.push(leftrec); // 分別加入堆疊中模擬 s.push(rightrec); } } } int main(void) { int list[]={5,4,2,12,6,13,10,20,8,2}; int size=sizeof(list)/sizeof(*list)-1; quicksort(list,0,size); for(int k=1;k<=size;k++) cout<<list[k]<<endl; system("PAUSE"); return 0; } -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 140.127.71.200 ※ 編輯: LiloHuang 來自: 140.127.71.200 (06/10 22:58)
kewang:大推呀! 06/10 22:59
-- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 163.23.22.28