1、delete t;在节点P后插入一个节点: bool listtype::insert(type t,int p)listnodetype *ptr;ptr=first;int k=1;while(ptr!=NULLkk+;if(ptr=NULLk!return false;elselistnodetype tp;tp=new listnodedata=t;next=ptrnext;ptr-next=tp;length+;return true;6 写一个函数,将其中的t都转换成4个空格。bool change(char *buf, int len) int count = 0; int i;
2、 / 统计有多少个t for (i = 0; bufi != 0; i+) if (bufi = t) count+; / 给定的buf空间是否能装下生成的字符串 int j = i + 3 * count; if (len j + 1) return false; / 从后向前逐个替换 while (count 0) while (bufi !t) bufj- = bufi-; count; bufj = bufj - 1 = bufj 2 = bufj 3 = ; j = 4; i-; return true;int main() char buf100 = 123t45ttt6tt65n
3、4234t5345 cout”Before chage:endl; coutbuf coutAfter calling the function: / buf是原字符串,100是buf的长度(要足够大,最好是原字符串的3倍) if (change(buf, 100) = true) cout buf while(ps) pe-next = psnext;psnext = head;head = ps;ps = pe-next;16 某个程序在一个嵌入式系统(200M的CPU,50M的SDRAM)中已经最化了,换到另一个系统(300M的CPU,50M的SDRAM)中运行,还需要优化吗?要。程序在
4、每时每刻都要优化,只要能找到可以优化的方法。优化有多种目的,在200M的CPU中可能需要以速度为重点优化,在300M的CPU中可能要以代码长度为目的优化。17。 下面哪种排序法对12354最快 Ca quick sort /快速排序b.buble sort /冒泡排序c.merge sort /归并排序18。 哪种结构,平均来讲,获取一个值最快 Ba。 binary tree /二叉树b。 hash table /散列表,哈希表c. stack /栈19 请问C+的类和C里面的struct有什么区别?c+的类的成员默认情况下是私有的,c的struct的成员默认情况下是公共的.20 请讲一讲析构
5、函数和虚函数的用法和作用?析构函数的名字和类名相同,没有返回值,没有参数,不能随意调用也没有重载.只是在类对象生命期结束时由系统自动调用。虚函数用在继承中,当在派生类中需要重新定义基类的函数时需要在基类中将该函数声明为虚函数,作用为使程序支持动态联编.21 全局变量和局部变量有什么区别?是怎么实现的?操作系统和编译器是怎么知道的?一些变量整个程序中都是可见的,它们称为全局变量,一些变量在函数内部定义且只在函数中可知,则称为局部变量。全局变量由编译器建立且存放在内存的全局数据区,局部变量存放在栈区.22 一些寄存器的题目,主要是寻址和内存管理等一些知识. 1、 立即寻址2、 寄存器寻址3、 直接
6、寻址4、 寄存器间接寻址5、 基址加变址寻址6、 寄存器相对寻址7、 相对基址加变址寻址 23 8086是多少位的系统?在数据总线上是怎么实现的?8086有16根数据线和20根地址线,因为可用20位地址.8086是16位处理器。24 多态。overload 和 override的区别。多态:接口的多种不同的实现方式即为多态重载在相同范围(同一个类中),函数名字相同,参数不同,virtual关键字可有可无.覆盖是指派生类函数覆盖基类函数,不同的范围,函数名字相同,参数相同,基类函数必须有virtual关键字.Sony笔试题25完成下列程序*.*.*。.。.*.。.。*.。.*.。.。*.。.。.
7、。.*.*。.。.*。.*.。.。.。*.。.。.。.*.。.。i ncludeiostreamusing namespace std;const int n = 8;main()int i;int j;int k;for(i = n; i = 1; i-)for(j = 0; j n-i+1; j+)cout”*for(k=1; k ni+1; k+)cout.endl;system(pause”)26 完成程序,实现对数组的降序排序i nclude iostreamvoid sort(int arr, int n);int array=45,56,76,234,1,34,23,2,3;so
8、rt(array, 9);for(int i = 0; i = 8; i+)/曾经在这儿出界coutarrayi ”;coutendl;pause”);void sort(int* arr, int n) int temp;for(int i = 1; i 9; i+)for(int k = 0; k 9 i; k+)/曾经在这儿出界if(arrk arrk + 1)temp = arrk;arrk = arrk + 1;arrk + 1 = temp; 27 费波那其数列,1,1,2,3,5编写程序求第十项.可以用递归,也可以用其他方法,但要说明你选择的理由.非递归i nclude iost
9、reamint Pheponatch(int n);int Ph = Pheponatch(10);Phsystem(”pause”);int Pheponatch(int n)int elem;int n1 = 1;int n2 = 1;if(n = 1 | n =2)return 1;for(int i = 3;= n;elem = n1 + n2;n1 = n2;n2 = elem;return elem; 递归using namespace std;int Pheponatch(int n);int n;cinn;int ph = Pheponatch(n);phtypedef str
10、uctTNode* left;TNode right;int value; TNode;TNode* root=NULL;void append(int N);append(63);append(45);append(32);append(77);append(96);append(21);append(17); / Again, 数字任意给出void append(int N)TNode NewNode=(TNode )malloc(sizeof(TNode);NewNodevalue=N;if(root=NULL)root=NewNode;return;TNode* temp;temp=r
11、oot;while(N=temp。value & temp.left!=NULL) | (N=temp.value & temp。left!=NULL)temp=temp。left;while(Ntemp。value & temp.right!right;if(N=temp。value)temp.left=NewNode;temp.right=NewNode;return; 29。 A class B network on the internet has a subnet mask of 255.255.240.0, what is the maximum number of hosts p
12、er subnet . 240 b。 255 c。 4094 d。 6553430。 What is the difference: between o(log n) and o(log n2), where both logarithems have base 2 。a. o(log n2) is bigger b。 o(log n) is biggerc. no difference31. For a class what would happen if we call a classs constructor from with the same classs constructor 。
13、a. compilation error b. linking errorc。 stack overflow d. none of the above32。 “new” in c+ is a: 。 library function like malloc in c key word c。 operatord. none of the above33。 Which of the following information is not contained in an inode . file owner b。 file size file name d。 disk address34。 What
14、s the number of comparisons in the worst case to merge two sorted lists containing n elements each .a. 2n b。2n-1 c.2n+1 d。2n-235. Time complexity 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。 n2 d。 nn36。 The num
15、ber of 1s in the binary representation of 34096+ 15256+516+3 are .a. 8 b。 9 c. 10 d。 1237设计函数 int atoi(char *s)。38int i=(j=4,k=8,l=16,m=32); printf(“%d”, i); 输出是多少?39解释局部变量、全局变量和静态变量的含义。40解释堆和栈的区别。栈区(stack)- 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其操作方式类似于数据结构中的栈。堆:一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回收 .注意它与数据结构中的堆
16、是两回事,分配方式倒是类似于链表.41论述含参数的宏与函数的优缺点. 1.函数调用时,先求出实参表达式的值,然后带入形参.而使用带参的宏只是进行简单的字符替换。2。函数调用是在程序运行时处理的,分配临时的内存单元;而宏展开则是在编译时进行的,在展开时并不分配内存单元,不进行值的传递处理,也没有“返回值”的概念。3。对函数中的实参和形参都要定义类型,二者的类型要求一致,如不一致,应进行类型转换;而宏不存在类型问题,宏名无类型,它的参数也无类型,只是一个符号代表,展开时带入指定的字符即可。宏定义时,字符串可以是任何类型的数据。4.调用函数只可得到一个返回值,而用宏可以设法得到几个结果。5.使用宏次
17、数多时,宏展开后源程序长,因为每展开一次都使程序增长,而函数调用不使源程序变长.6.宏替换不占运行时间,只占编译时间;而函数调用则占运行时间(分配单元、保留现场、值传递、返回)。一般来说,用宏来代表简短的表达式比较合适。42. 以下三条输出语句分别输出什么?C易char str1 = ”abcchar str2 = ”abcconst char str3 = ”abc”;const char str4 = ”abcconst char* str5 = abc”;const char* str6 = ”abccout boolalpha ( str1=str2 ) endl; / 输出什么?co
18、ut boolalpha ( str3=str4 ) / 输出什么? boolalpha ( str5=str6 ) endl;1答:分别输出false,false,true。str1和str2都是字符数组,每个都有其自己的存储区,它们的值则是各存储区首地址,不等;str3和str4同上,只是按const语义,它们所指向的数据区不能修改。str5和str6并非数组而是字符指针,并不分配存储区,其后的“abc以常量形式存于静态数据区,而它们自己仅是指向该区首地址的指针,相等。43。 非C+内建型别 A 和 B,在哪几种情况下B能隐式转化为A?C+中等BDa. class B : public A
19、 / B公有继承自A,可以是间接继承的 class B operator A( ); / B实现了隐式转化为A的转化c. class A A( const B ); / A实现了non-explicit的参数为B(可以有其他带默认值的参数)构造函数d。 A& operator= ( const A ); / 赋值操作,虽不是正宗的隐式类型转换,但也可以勉强算一个44. 以下代码中的两个sizeof用法有问题吗?void UpperCase( char str ) / 将 str 中的小写字母转换成大写字母for( size_t i=0; isizeof(str)/sizeof(str0); +i )if( a=stri stri=z )stri -= (aA );char str = aBcDe”; str字符长度为: ” sizeof(str)/sizeof(str0) endl;UpperCase( str );cout str 9 ) cl += (A-91); ch cl ;char str = I love 中国”; istrlen(str);char2Hex( stri ); endl;4
copyright@ 2008-2022 冰豆网网站版权所有
经营许可证编号:鄂ICP备2022015515号-1