Lumia 920的sensor果然是垃圾# PDA - 掌中宝
r*n
1 楼
假如我写了个linklist的类,如下:
template
struct Node
{
T data;
Node* next;
};
template
class List
{
public:
List():head(NULL){};
List(const Node *inNode):head(inNode){};
~List(){destroy();};
void addToHead( const T &item );
void print( ostream &out ) const;
void reverse();
void destroy();
private:
Node *head;
};
//iterative reverse
template
void List::reverse()
{
if (!head) //empty list
return;
Node *prev=NULL;
Node *curr = head;
while (curr)
{
Node *next = curr->next;
curr->next=prev;
prev=curr;
curr=next;
}
head=prev;
}
有可能把这个成员函数改成递归的写法吗?
(http://www.ihas1337code.com/category/linked-list/page/2)
很久没写C++了,语法都忘记了...........
template
struct Node
{
T data;
Node* next;
};
template
class List
{
public:
List():head(NULL){};
List(const Node *inNode):head(inNode){};
~List(){destroy();};
void addToHead( const T &item );
void print( ostream &out ) const;
void reverse();
void destroy();
private:
Node
};
//iterative reverse
template
void List
{
if (!head) //empty list
return;
Node
Node
while (curr)
{
Node
curr->next=prev;
prev=curr;
curr=next;
}
head=prev;
}
有可能把这个成员函数改成递归的写法吗?
(http://www.ihas1337code.com/category/linked-list/page/2)
很久没写C++了,语法都忘记了...........