【正文】
nd(int N)。int main(){append(63)。append(45)。append(32)。append(77)。append(96)。append(21)。append(17)。 // Again, 數(shù)字任意給出}void append(int N){TNode* NewNode=(TNode *)malloc(sizeof(TNode))。NewNodevalue=N。if(root==NULL){root=NewNode。return。}else{TNode* temp。temp=root。while((N= amp。amp。 !=NULL) || (Ntemp. value amp。amp。 !=NULL)){while(N= amp。amp。 !=NULL)temp=。while(N amp。amp。 !=NULL)temp=。}if(N=)=NewNode。else=NewNode。return。 }}29. A class B network on the internet has a subnet mask of , what is the maximum number of hosts per subnet .a. 240 b. 255 c. 4094 d. 6553430. What is the difference: between o(log n) and o(log n^2), where both logarithems have base 2 .a. o(log n^2) is bigger b. o(log n) is biggerc. no difference31. For a class what would happen if we call a class’s constructor from with the same class’s constructor .a. pilation error b. linking errorc. stack overflow d. none of the above32. “new” in c++ is a: .a. library function like malloc in cb. key word c. operatord. none of the above33. Which of the following information is not contained in an inode .a. file owner b. file sizec. file name d. disk address34. What’s the number of parisons in the worst case to merge two sorted lists containing n elements each .a. 2n +1 35. Time plexity of n algorithm T(n), where n is the input size ,is T(n)=T(n1)+1/n if n1 otherwise 1 the order of this algorithm is .a. log (n) b. n c. n^2 d. n^n36. The number of 1’s in the binary representation of 3*4096+ 15*256+5*16+3 are .a. 8 b. 9 c. 10 d. 1237.設(shè)計(jì)函數(shù) int atoi(char *s)。 38.int i=(j=4,k=8,l=16,m=32)。 printf(“%d”, i)。 輸出是多少? 39.解釋局部變量、全局變量和靜態(tài)變量的含義。 40.解釋堆和棧的區(qū)別。 棧區(qū)(stack)— 由編譯器自動(dòng)分配釋放 ,存放函數(shù)的參數(shù)值,局部變量的值等。其操作方式類似于數(shù)據(jù)結(jié)構(gòu)中的棧。堆:一般由程序員分配釋放, 若程序員不釋放,程序結(jié)束時(shí)可能由OS回收 。注意它與數(shù)據(jù)結(jié)構(gòu)中的堆是兩回事,分配方式倒是類似于鏈表.41.論述含參數(shù)的宏與函數(shù)的優(yōu)缺點(diǎn)。 ,先求出實(shí)參表達(dá)式的值,然后帶入形參。而使用帶參的宏只是進(jìn)行簡(jiǎn)單的字符替換。,分配臨時(shí)的內(nèi)存單元;而宏展開(kāi)則是在編譯時(shí)進(jìn)行的,在展開(kāi)時(shí)并不分配內(nèi)存單元,不進(jìn)行值的傳遞處理,也沒(méi)有“返回值”的概念。,二者的類型要求一致,如不一致,應(yīng)進(jìn)行類型轉(zhuǎn)換;而宏不存在類型問(wèn)題,宏名無(wú)類型,它的參數(shù)也無(wú)類型,只是一個(gè)符號(hào)代表,展開(kāi)時(shí)帶入指定的字符即可。宏定義時(shí),字符串可以是任何類型的數(shù)據(jù)。,而用宏可以設(shè)法得到幾個(gè)結(jié)果。,宏展開(kāi)后源程序長(zhǎng),因?yàn)槊空归_(kāi)一次都使程序增長(zhǎng),而函數(shù)調(diào)用不使源程序變長(zhǎng)。,只占編譯時(shí)間;而函數(shù)調(diào)用則占運(yùn)行時(shí)間(分配單元、保留現(xiàn)場(chǎng)、值傳遞、返回)。 一般來(lái)說(shuō),用宏來(lái)代表簡(jiǎn)短的表達(dá)式比較合適。42. 以下三條輸出語(yǔ)句分別輸出什么?[C易]char str1[] = abc。char str2[] = abc。const char str3[] = abc。 const char str4[] = abc。 const char* str5 = abc。const char* str6 = abc。cout boolalpha ( str1==str2 ) endl。 // 輸出什么?0cout boolalpha ( str3==str4 ) endl。 // 輸出什么?0cout boolalpha ( str5==str6 ) endl。 // 輸出什么?1答:分別輸出false,false,true。str1和str2都是字符數(shù)組,每個(gè)都有其自己的存儲(chǔ)區(qū),它們的值則是各存儲(chǔ)區(qū)首地址,不等;str3和str4同上,只是按const語(yǔ)義,它們所指向的數(shù)據(jù)區(qū)不能修改。str5和str6并非數(shù)組而是字符指針,并不分配存儲(chǔ)區(qū),其后的“abc”以常量形式存于靜態(tài)數(shù)據(jù)區(qū),而它們自己僅是指向該區(qū)首地址的指針,相等。43. 非C++內(nèi)建型別 A 和 B,在哪幾種情況下B能隱式轉(zhuǎn)化為A?[C++中等]答:BDa. class B : public A { ……} // B公有繼承自A,可以是間接繼承的b. class B { operator A( )。 } // B實(shí)現(xiàn)了隱式轉(zhuǎn)化為A的轉(zhuǎn)化c. class A { A( const Bamp。 )。 } // A實(shí)現(xiàn)了nonexplicit的參數(shù)為B(可以有其他帶默認(rèn)值的參數(shù))構(gòu)造函數(shù)d. Aamp。 operator= ( const Aamp。 )。 // 賦值操作,雖不是正宗的隱式類型轉(zhuǎn)換,但也可以勉強(qiáng)算一個(gè)44. 以下代碼中的兩個(gè)sizeof用法有問(wèn)題嗎?[C易]void UpperCase( char str[] ) // 將 str 中的小寫(xiě)字母轉(zhuǎn)換成大寫(xiě)字母{for( size_t i=0。 isizeof(str)/sizeof(str[0])。 ++i )if( 39。a39。=str[i] amp。amp。 str[i]=39。z39。 )str[i] = (39。a39。39。A39。 )。}char str[] = aBcDe。cout str字符長(zhǎng)度為: sizeof(str)/sizeof(str[0]) endl。UpperCase( str )。cout str endl。45. 以下代碼有什么問(wèn)題?[C難]void char2Hex( char c ) // 將字符以16進(jìn)制表示{char ch = c/0x10 + 39。039。 if( ch 39。939。 ) ch += (39。A39。39。939。1)。char cl = c%0x10 + 39。039。 if( cl 39。939。 ) cl += (39。A39。39。939。1)。cout ch cl 39。 39。}char str[] = I love 中國(guó)。for( size_t i=0。 istrlen(str)。 ++i )char2Hex( str[i] )。cout endl。46. 以下代碼有什么問(wèn)題?[C++易]struct Test{Test( int ) {}Test() {}void fun() {}}。void main( void ){Test a(1)。()。Test b()。()。}*** Test b()。//定義了一個(gè)函數(shù)47. 以下代碼有什么問(wèn)題?[C++易]cout (true?1:1) endl。8. 以下代碼能夠編譯通過(guò)嗎,為什么?[C++易]unsigned int const size1 = 2。char str1[ size1 ]。unsigned int temp = 0。cin temp。unsigned int const size2 = temp。char str2[ size2 ]。48. 以下代碼中的輸出語(yǔ)句輸出0嗎,為什么?[C++易]struct CLS{int m_i。CLS( int i ) : m_i(i) {}CLS(){CLS(0)。}}。CLS obj。cout endl。49. C++中的空類,默認(rèn)產(chǎn)生哪些類成員函數(shù)?[C++易]答:class Empty{public:Empty()。 // 缺省構(gòu)造函數(shù)Empty( const Emptyamp。 )。 // 拷貝構(gòu)造函數(shù)~Empty()。 // 析構(gòu)函數(shù)Emptyamp。 operator=( const Emptyamp。 )。 // 賦值運(yùn)算符Empty* operatoramp。()。 // 取址運(yùn)算符const Empty* operatoramp。() const。 // 取址運(yùn)算符 const}。50. 以下兩條輸出語(yǔ)句分別輸出什么?[C++難]float a = 。cout (int)a endl。cout (intamp。)a endl。cout boolalpha ( (int)a == (intamp。)a ) endl。 // 輸出什么0float b = 。cout (int)b endl。cout (intamp。)b endl。cout boolalpha ( (int)b == (intamp。)b ) endl。 // 輸出151. 以下反向遍歷array數(shù)組的方法有什么錯(cuò)誤?[STL易]vector array。( 1 )。( 2 )。( 3 )。for( vector::size_type i=()1。 i=0。 i ) // 反向遍歷array數(shù)組{cout array[i] endl。}52. 以下代碼有什么問(wèn)題?[STL易]typedef vector IntArray。IntArray array。( 1 )。( 2 )。( 2 )。( 3 )。// 刪除array數(shù)組中所有的2for( IntArray::iterator itor=()。 itor!=()。 ++itor ){if( 2 == *itor ) ( itor )。}53. 寫(xiě)一個(gè)函數(shù),完成內(nèi)存之間的拷貝。[考慮問(wèn)題是否全面]答:void* mymemcpy( void *dest, const void *src, size_t count ){char* pdest = static_castchar*( dest )。const char* psrc = static_castconst char*( src )。if( pdestpsrc amp。amp。 pdestpsrc+cout ) 能考慮到這種情況就行了{(lán)for( size_t i=count1。 i!=1。 i )pdest[i] = psrc[i]。}else{for( size_t i=0。 icount。 ++i )pdest[i] = psrc[i]。}return dest。}int main( void ){char str[] = 0123456789。mymemcpy( str+1, str+0, 9 )。cout str endl。system( Pause )。return 0。}54 線程與進(jìn)程的區(qū)別進(jìn)程就是一個(gè)應(yīng)用程序在處理機(jī)上的一次執(zhí)行過(guò)程,它是一個(gè)動(dòng)態(tài)的概念,而線程是進(jìn)程中的一部分,進(jìn)程包含多個(gè)線程在運(yùn)行。55:請(qǐng)你分別劃劃OSI(開(kāi)放式系統(tǒng)互聯(lián))的七層網(wǎng)絡(luò)結(jié)構(gòu)圖,和TCP/IP的五層結(jié)構(gòu)圖? 56:請(qǐng)你詳細(xì)的解釋一下IP協(xié)議的定義,在哪個(gè)層上面,主要有什么作用? TCP與UDP呢? IP協(xié)議是網(wǎng)絡(luò)層的協(xié)議,它實(shí)現(xiàn)了Internet中自動(dòng)路由的功能,即尋徑的功能,TCP協(xié)議是一個(gè)傳輸性的協(xié)議它向下屏蔽了IP協(xié)議不可靠傳輸?shù)奶匦?,向上提供一個(gè)可靠的點(diǎn)到點(diǎn)的傳輸,UDP提供的是一種無(wú)連接的服務(wù),主要考慮到很多應(yīng)用不需要可靠的連接,但需要快速的傳輸57:請(qǐng)問(wèn)交換機(jī)和路由器分別的實(shí)現(xiàn)原理是什么?分別在哪個(gè)層次上面實(shí)現(xiàn)的?