1)給一個單項鍊表的頭,把它反轉
struct my_link { int data; struct my_link *next; }; struct my_link *inverselink(struct my_link *inlink) { struct my_link *t; t=inlink; struct my_link *head,*p; head=p=NULL; while(t!=NULL) { p=calloc(sizeof(struct my_link),1); p->data=t->data; p->next=head; head=p; t=t->next; } return head; }
2)const 放在函數的前後面分別有什麼區別?
如果是void f(const int a);這種形式的,那麼表示a的值在函數中不能被修改, 當然這兒只是個形式,void f(int a);這種方式,a的值也不會被修改。 如果是void f(...) const;這種形式,這一般是類的成員 函數 , 表示這個成員函數不會修改類的成員變量,如果有修改成員變量,那麼會編譯錯誤的