/* * 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); }
时间: 2024-10-16 22:10:44