The C Programming Language ¾µä´úÂë any(s1,s2)
/*
* Exercise 2-5 Page 48
*
* Write the function any(s1,s2), which returns the first location
* in the string s1 where any character from the string s2 occurs,
* or -1 if s1 contains no characters from s2. (The standard library
* function strpbrk does the same job but returns a pointer to the
* location.)
*
*/
Here's a much better solution, by Partha Seetala. This solution has a worst-
case time complexity of only O(n + m) which is considerably better.
Ïà¹ØÎĵµ£º
ÔÚc++ÖдæÔÚ£¬ÔÚcÓïÑÔÖÐÈ´²»´æÔÚµÄÏÞÖÆÓУº
1. ÍêÕûµÄº¯ÊýÔÐÍÉùÃ÷ÊDZØÐëµÄ£¬cÓïÑÔÀïûÕâôÑϸñ.
2. c++ÖУ¬ÓÉtypedef¶¨ÒåµÄÃû×Ö²»ÄÜÓëÒÑÓеĽṹ±êÇ©³åÍ»£¬µ«ÊÇcÓïÑÔÖÐÈ´ÊÇ¿ÉÒÔµÄ.
3. µ±void*Ö¸Õ븳ֵ¸øÁíÒ»¸öÀàÐ͵ÄÖ¸Õëʱ£¬c++¹æ¶¨±ØÐë½øÐÐÇ¿ÖÆÀàÐÍת»»£¬µ«ÊÇcÓïÑÔÖÐÈ´²»±ØÒª¡£
ÔÚc++ºÍcÖк¬Òå²»Ò»ÑùµÄÌØÐÔ£º
1. c++ ......
ʲôÊÇ¿ÕÖ¸Õë³£Á¿£¨null pointer constant£©?
[6.3.2.3-3] An integer constant expression with the value 0, or such an expression cast to type void *, is called a null pointer constant.
ÕâÀï¸æËßÎÒÃÇ£º0¡¢0L¡¢'\0'¡¢3 - 3¡¢0 * 17 £¨ËüÃǶ¼ÊÇ“integer constant expression”£©ÒÔ¼° (void*)0 µÈ¶¼ÊÇ¿Õ ......
Èç¹ûC++µ÷ÓÃÒ»¸öCÓïÑÔ±àдµÄ.DLLʱ£¬µ±°üÀ¨.DLLµÄÍ·Îļþ»òÉùÃ÷½Ó¿Úº¯Êýʱ£¬Ó¦¼Óextern "C" {¡¡}¡£
È磺
Í·ÎļþcExample.h
#include <stdio.h>
#ifndef C_EXAMPLE_H
#define C_EXAMPLE_H
int add(int x,int y);
#endif
º¯ÊýʵÏÖÎļþcExample.c(×¢ÒâÊÇ.cÎļþ)
#include<stdio.h>
#include "cExample ......
Ñ¡ÔñÅÅÐò·¨ÀàËÆÎÒÃÇÈËΪµÄÅÅÐòϰ¹ß£º´ÓÊý¾ÝÖÐÑ¡Ôñ×îСµÄͬµÚÒ»¸öÖµ½»»»£¬ÔÚ´ÓʡϵIJ¿·ÖÖÐÑ¡Ôñ×îСµÄÓëµÚ¶þ¸ö½»»»£¬ÕâÑùÍù¸´ÏÂÈ¥……
Ñ¡ÔñÅÅÐòµÄƽ¾ùʱ¼ä¸´ÔӶȱÈðÅÝÅÅÐòµÄÉÔµÍ:
ͬÑùÊý¾ÝµÄÇé¿öÏ£¬2ÖÖËã·¨µÄÑ»·´ÎÊýÊÇÒ»ÑùµÄ£¬µ«Ñ¡ÔñÅÅÐòÊÇÒ»¶Ô¶àµÄ±È½Ï£¬Ã¿ÌËÖ»½øÐÐ0µ½1´Î½»»»£¬¶øÃ°ÅÝÅÅÐòÊÇÏàÁÚÁ½Á½±È½Ï£ ......