華為面試題:怎麼判斷鍊錶中是否有環?
bool circleinlist(link* phead)
if(ptemp = = ptemp1)
return (true);
return (false);
}兩個字串,s,t;把t字串插入到s字串中,s字串有足夠的空間存放t字串
void insert(char *s, char *t, int i)
1。編寫乙個 c 函式,該函式在乙個字串中找到可能的最長的子字串,且該字串是由同一字元組成的。
char * search(char *cpsource, char ch)
++cpsource;
}return cpdest;
}2。請編寫乙個 c 函式,該函式在給定的記憶體區域搜尋給定的字元,並返回該字元所在位置索引值。
int search(char *cpsource, int n, char ch)
乙個單向鍊錶,不知道頭節點,乙個指標指向其中的乙個節點,問如何刪除這個指標指向的節點?
將這個指標指向的next節點值copy到本節點,將next指向next->next,並隨後刪除原next指向的節點。
#include
void foo(int m, int n)
int main()
輸出:m=7,n=4,b=7(vc6.0)
這種方式和編譯器中得函式呼叫關係相關即先後入棧順序。不過不同
編譯器得處理不同。也是因為c標準中對這種方式說明為未定義,所以
各個編譯器廠商都有自己得理解,所以最後產生得結果完全不同。
因為這樣,所以遇見這種函式,我們首先要考慮我們得編譯器會如何處理
這樣得函式,其次看函式得呼叫方式,不同得呼叫方式,可能產生不同得
結果。最後是看編譯器優化。
2.寫一函式,實現刪除字串str1中含有的字串str2.
第二個就是利用乙個kmp匹配演算法找到str2然後刪除(用鍊錶實現的話,便捷於陣列)
//author: azhen
#include
#include
#include
char *commanstring(char shortstring, char longstring)
}return null;
}main()
11.寫乙個函式比較兩個字串str1和str2的大小,若相等返回0,若str1大於
str2返回1,若str1小於str2返回-1
int strcmp ( const char * src,const char * dst)
if ( ret < 0 )
ret = -1 ;
else if ( ret > 0 )
ret = 1 ;
return( ret );
}3,求1000!的未尾有幾個0(用素數相乘的方法來做,如72=2*2*2*3*3);
求出1->1000裡,能被5整除的數的個數n1,能被25整除的數的個數n2,能被125整除的數的個數n3,
能被625整除的數的個數n4.
1000!末尾的零的個數=n1+n2+n3+n4;
#include
#define num 1000
int find5(int num)
return ret;
}int main()
printf(" the total zero number is %d\n",result);
return 0;}
1. 有雙向迴圈鍊錶結點定義為:
struct node
;有兩個雙向迴圈鍊錶a,b,知道其頭指標為:pheada,pheadb,請寫一函式將兩煉表中data值相同的結點刪除
bool detelenode(node *pheader, datatype value)
else
pnode->front->next = pnode->next;
}node *pnextnode = pnode->next;
delete pnode;
pnode = pnextnode;
bret = true;
//不要break或return, 刪除所有
}else
}return bret;
}void de(node *pheada, node *pheadb)
node *pnode = pheada;
while (pnode != null)
else
}node *pnextnode = pnode->next;
delete pnode;
pnode = pnextnode;
}else}}
2. 程式設計實現:找出兩個字串中最大公共子字串,如"abccade","dgcadde"的最大子串為"cad"
int getcommon(char *s1, char *s2, char **r1, char **r2)}}
}3. 程式設計實現:把十進位制數(long型)分別以二進位制和十六進製制形式輸出,不能使用printf系列庫函式
char* test3(long num)
return buffer;}
輸入n, 列印 n*n 矩陣
比如 n = 3,列印:
1 2 3
8 9 4
7 6 5
n = 4,列印:
1 2 3 4
12 13 14 5
11 16 15 6
10 9 8 7
解答:1 #define n 15
int s[n][n];
void main()
for( i = 0; i < n; i++ )
}2 define max_n 100
int matrix[max_n][max_n];
華為C語言面試題
華為c語言面試題集 c語言面試題 華為c語言面試題深圳華為面試 1 區域性變數能否和全域性變數重名?答 能,區域性會遮蔽全域性。要用全域性變數,需要使用 區域性變數可以與全域性變數同名,在函式內引用這個變數時,會用到同名的區域性變數,而不會用到全域性變數。對於有些編譯器而言,在同乙個函式內可以定義多...
c語言面試題之華為面試題
1 區域性變數能否和全域性變數重名?答 能,區域性會遮蔽全域性。要用全域性變數,需要使用 區域性變數可以與全域性變數同名,在函式內引用這個變數時,會用到同名的區域性變數,而不會用到全域性變數。對於有些編譯器而言,在同乙個函式內可以定義多個同名的區域性變數,比如在兩個迴圈體內都定義乙個同名的區域性變數...
華為經典C語言面試題ss
重解幾道華為經典c語言面試題 1 找錯 void test1 這裡string陣列越界,因為字串長度為10,還有乙個結束符 0 所以總共有11個字元長度。string陣列大小為10,這裡越界了。ps 使用strcpy函式的時候一定要注意前面目的陣列的大小一定要大於後面字串的大小,否則便是訪問越界。v...