Groups
Groups
Sign in
Groups
Groups
Code fellow's playground
Conversations
About
Send feedback
Help
[程式]通用型別
8 views
Skip to first unread message
cpyi
unread,
Dec 25, 2012, 2:46:33 PM
12/25/12
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to code_fellow...@googlegroups.com
通用型別就是讓一個函數可以處理多種型別的資料。在C++裡有專門處理多型的方法,C也有C處理的方式,不過大量依賴指標的操作。
舉例而言,一般我們排序都是排序數字,但是有些資料可能比單純的數字更為複雜,像是結構體,我們想要用結構體中的某個元素來做排序,這樣子可能就要重新寫一個程式,造成時間浪費。
在這裡我模仿qsort的方式,寫了一個以氣泡排序(較慢,實作容易)為基底算法的通用型別排序方法。在這裡我是以函式庫方式呈現,main.c調用這個函式庫。
函式庫的編譯方法就是先編譯好函式庫,在使用時引入函式定義,並做好連結即可使用。如果有興趣我再詳細說明。之後會應該會再補上很多函式到libcp裡面。
範例code:
www.nba.nctu.edu.tw/~cpyi/libcp.h
www.nba.nctu.edu.tw/~cpyi/libcp.c
www.nba.nctu.edu.tw/~cpyi/main.c
Reply all
Reply to author
Forward
0 new messages