本文发表在 rolia.net 枫下论坛** Reverse a string
char *strrev(char *str)
{
if (str) {
char *s=str, *e = s + strlen(s);
while(s<e) { char tmp=*--e; *e=*s; *s++=tmp; }
}
return str;
}
** Reverse a link list
Node *reverse(Node *list)
{
Node *newlist=0;
while(list)
{
Node *tmp= list;
list = list->next;
tmp->next = newlist;
newlist = tmp;
}
return newlist;
}
** Remove all elements with a given value from a list
void remove(Node **node, int v)
{
while (*node) {
if ((*node)->value = v) {
Node *tmp = *node;
*node = (*node)->next;
free(tmp);
} else node = &(*node)->next;
}
}
** Remove all elements with a given value from a list
void remove(Node **node, int v)
{
while (*node) {
if ((*node)->value = v) {
Node *tmp = *node;
*node = (*node)->next;
free(tmp);
} else node = &(*node)->next;
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net
char *strrev(char *str)
{
if (str) {
char *s=str, *e = s + strlen(s);
while(s<e) { char tmp=*--e; *e=*s; *s++=tmp; }
}
return str;
}
** Reverse a link list
Node *reverse(Node *list)
{
Node *newlist=0;
while(list)
{
Node *tmp= list;
list = list->next;
tmp->next = newlist;
newlist = tmp;
}
return newlist;
}
** Remove all elements with a given value from a list
void remove(Node **node, int v)
{
while (*node) {
if ((*node)->value = v) {
Node *tmp = *node;
*node = (*node)->next;
free(tmp);
} else node = &(*node)->next;
}
}
** Remove all elements with a given value from a list
void remove(Node **node, int v)
{
while (*node) {
if ((*node)->value = v) {
Node *tmp = *node;
*node = (*node)->next;
free(tmp);
} else node = &(*node)->next;
}
}更多精彩文章及讨论,请光临枫下论坛 rolia.net