[轉錄][情報] BBS 程式碼標色小工具
※ [本文轉錄自 EZsoft 看板]
作者: LiloHuang (築夢踏實) 看板: EZsoft
標題: [情報] BBS 程式碼標色小工具
時間: Sun Jun 10 22:51:30 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:轉錄至看板 share 06/10 22:58
推
06/10 22:58,
06/10 22:58
推
06/10 22:59,
06/10 22:59
→
06/10 23:00,
06/10 23:00
推
06/10 23:03,
06/10 23:03
推
06/10 23:03,
06/10 23:03
推
06/10 23:07,
06/10 23:07
推
06/10 23:21,
06/10 23:21
推
06/11 00:37,
06/11 00:37
推
06/11 08:07,
06/11 08:07
推
06/11 10:25,
06/11 10:25
推
06/11 10:32,
06/11 10:32
推
06/11 13:29,
06/11 13:29
推
06/11 13:29,
06/11 13:29
推
06/11 14:17,
06/11 14:17
推
06/11 16:23,
06/11 16:23
推
06/11 16:23,
06/11 16:23
推
06/11 19:00,
06/11 19:00
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 122.100.180.172