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°æ±¾£º
vim stash.h
#ifndef STASH_H
#define STASH_H
typedef struct STASHTag {
int size; /* Size of each space */
int quantity; /* Number of storage spaces */
int next; /* Next empty space */
/* Dynamically allocated array of bytes: */
unsigned char* ......
È¥Äê ÎÒÃÇͨ¹ýÁ˼ÆËã»ú¶þ¼¶µÄ¿¼ºË£¬½ÓÏÂÀ´ÃæÁٵľÍÊÇÈý¼¶µÄ¿¼ÑéÁË£¬
ÓôÃÆµÄÊÇ ²»ÖªµÀÊÇÑ¡ÔñÄÄÖÖÓïÑԺã¡
Èý¼¶ÉÏ»ú ¹æ¶¨µÄÓïÑÔÊÇCÓïÑÔ£¬ÎÒѧµÄÊÇC++£¬ÀÏʦ˵£ºÕâ¶ÔÄãµÄÉÏ»ú¿¼ÊÔʱÓÐÓ°ÏìµÄ£¡
´Ó³¤Ô¶½Ç¶È¿´£ºC++±ÈCÓïÑÔÓÐןü¼Ó¹ãÀ«µÄǰ¾°£»¶øCÓïÑÔ¶ÔÓÚÉÏ»ú¿¼ÊÔ ºÃÈÝÒ×ÉÏÊÖ£¡
ÓôÃÆ¡£¡£¡£¡£¡£¡£ ......
Ò»¡¢»ù±¾ÖªÊ¶
Ö¸ÕëºÍÒýÓõÄÉùÃ÷·½Ê½£º
ÉùÃ÷Ö¸Õ룺 char* pc;
ÉùÃ÷ÒýÓ㺠char c = 'A'
char& rc = c;
ËüÃǵÄÇø±ð£º
¢Ù´ÓÏÖÏóÉÏ¿´£¬Ö¸ÕëÔÚÔËÐÐʱ¿ÉÒԸıäÆäËùÖ¸ÏòµÄÖµ£¬¶øÒýÓÃÒ»µ©ºÍij¸ö¶ÔÏó°ó¶¨ºó ......
1 ÎĵµËµÃ÷
2 Îļþ½á¹¹
2.1 ΪÁ˸üºÃµÄÀûÓÃCVSµÄÐ޸ļǼ¹¦ÄÜ£¬ÔÚcommitµÄʱºò£¬ÈÏÕæµÄÌîдÐ޸ļǼ¡£
2.2 Ϊ·ÀֹͷÎļþ±»Öظ´ÒýÓã¬Ó¦µ±ÓÃifndef/define/endif½á¹¹²úÉúÔ¤´¦Àí¿é£»
2.3 ʹÓÃ__cplusplusºê¶¨Ò壬ʹ³ÌÐò¿ÉÒÔ·½±ãµÄÒÆÖ²ÖÁC++»·¾³Ï£»
2.4 Óà #include ¸ñʽÀ´ÒýÓñê×¼¿âµÄÍ·Îļþ£¨±àÒëÆ÷½«´Ó±ê×¼¿âĿ¼¿ªÊ ......
CÓïÑԵĻص÷º¯Êý˼Ïë´úÂ룺
#include <stdio.h>
void *max(void *base, unsigned int nmemb, unsigned int size,
int (*compar)(const void *, const void *))
{
int i;
void* max_data = base;
char* tmp = base;
&nbs ......