小程序 - 去字符串空格/二叉树查找

/*
 * Remove all the white spaces from a string.
 */
void removeWB(char* str)
{
    char* p;

    for (p = str; *str; str++)
        if (*str != ' ')
            *p++ = *str;
    *p = '\0';
}

 

查找某给定值在排序二叉树中是否存在.

#include <stdio.h>

typedef struct Node {
    int val;
    struct Node *left, *right;
} Node;

typedef enum {FOUND, NOT_FOUND} EXISTS;

EXISTS exists(Node *root, int target) 
{
    if (!root)
        return NOT_FOUND;
    if (root->val == target)
        return FOUND;
    return (target < root->val)
        ? exists(root->left, target)
        : exists(root->right, target);
}

 

posted @ 2016-03-21 13:31  brayden  阅读(647)  评论(0编辑  收藏  举报