华为笔试题

1.static有什么用途?(请至少说明两种)

    1)在函数体,一个被声明为静态的变量在这一函数被调用过程中维持其值不变。

    2) 在模块内(但在函数体外),一个被声明为静态的变量可以被模块内所有函数访问,但不能被模块外其它函数访问。它是一个本地的全局变量。

    3)在模块内,一个被声明为静态的函数只可被这一模块内的其它函数调用。那就是,这个函数被限制在声明它的模块的本地范围内使用

2.引用与指针有什么区别?

    1) 引用必须被初始化,指针不必。

    2) 引用初始化以后不能被改变,指针可以改变所指的对象。

    3) 不存在指向空值的引用,但是存在指向空值的指针。

3.描述实时系统的基本特性

       在特定时间内完成特定的任务,实时性与可靠性。

4.全局变量和局部变量在内存中是否有区别?如果有,是什么区别?

      全局变量储存在静态数据库(全局区),局部变量在堆栈。

5.什么是平衡二叉树?

      左右子树都是平衡二叉树 且左右子树的深度差值的绝对值不大于1。

6.堆栈溢出一般是由什么原因导致的?

      没有回收垃圾资源。

7.什么函数不能声明为虚函数?

     constructor函数不能声明为虚函数。

8.冒泡排序算法的时间复杂度是什么?

      时间复杂度是O(n^2)。

9.写出float x 与“零值”比较的if语句。

      if(x>0.000001&&x<-0.000001)

10.Internet采用哪种网络协议?该协议的主要层次结构?

      Tcp/Ip协议

      主要层次结构为: 应用层/传输层/网络层/数据链路层/物理层。

11.Internet物理地址和IP地址转换采用什么协议?

      ARP (Address Resolution Protocol)(地址解析协议)

12.IP地址的编码分为哪俩部分?

     IP地址由两部分组成,网络号和主机号。不过是要和“子网掩码”按位与上之后才能区分哪些是网络位哪些是主机位。

13.用户输入M,N值,从1至N开始顺序循环数数,每数到M输出该数值,直至全部输出。写出C程序。有些,M,N值可能导致不能全部输出

     循环链表,用取余操作做

我的答案:

  1. #include "iostream" 
  2. #include "stdio.h" 
  3. using namespace std; 
  4. struct Node  
  5.     int data;//存储1-N的值 
  6.     bool flag;//标记是否已被输出 
  7.     Node *next; 
  8. }; 
  9. //建立链表,循环链表,尾节点指向首节点,表长度为N,节点的数据值为1---N 
  10. Node* init(int N) 
  11.     Node * head=NULL; 
  12.     Node *q=NULL; 
  13.     for (int i=1;i<=N;i++) 
  14.     { 
  15.         if (i==1) 
  16.         { 
  17.             Node *p=(Node *)malloc(sizeof(Node)); 
  18.             p->data=i; 
  19.             p->flag=false
  20.             head=p; 
  21.             q=p; 
  22.             q->next=head; 
  23.          
  24.         } 
  25.         else 
  26.         { 
  27.             Node *p=(Node *)malloc(sizeof(Node)); 
  28.             p->data=i;p->flag=false
  29.             q->next=p; 
  30.             q=p; 
  31.             q->next=head;     
  32.         } 
  33.     } 
  34.     return head; 
  35. //打印所建立的循环链表,测试建表成功 
  36. void printLink(Node *head) 
  37.     Node *p=head; 
  38.      
  39.     do
  40.         cout<<p->data<<", "
  41.         p=p->next; 
  42.     }while (p!=head); 
  43.     cout<<endl; 
  44. //判断是否还有没有打印出来的节点 
  45. int isallflag(Node * head) 
  46.     Node *p=head; 
  47.     int k=0; 
  48.     do
  49.         if (p->flag==false
  50.         { 
  51.             k=1; 
  52.         } 
  53.         p=p->next; 
  54.          
  55.     }while (p!=head); 
  56.     return k; 
  57. //功能函数,约瑟夫环,打印出一个标记一个点,直至都打印出来 
  58. void fun(Node * head,int m) 
  59.     Node *p=head; 
  60.    int ct=1; 
  61.    while (isallflag(head)==1) 
  62.    { 
  63.        
  64.      
  65.        if (ct==m) 
  66.        { 
  67.            if (p->flag==false
  68.            { 
  69.                 p->flag=true
  70.                 cout<<p->data<<endl; 
  71.              
  72.            } 
  73.             ct=1; 
  74.             p=p->next; 
  75.             
  76.        } 
  77.        else 
  78.        { 
  79.            ct++; 
  80.            p=p->next; 
  81.        } 
  82.    } 
  83. int main(void)   
  84. {   
  85.     int m=0,n=0; 
  86.     cout<<"input m,n\n"
  87.     cin>>m; 
  88.     cin>>n; 
  89.     Node *head=init(n); 
  90.     fun(head,m); 
  91.     return 0;   
  92. }   
#include "iostream"
#include "stdio.h"
using namespace std;
struct Node 
{
	int data;//存储1-N的值
	bool flag;//标记是否已被输出
	Node *next;
};
//建立链表,循环链表,尾节点指向首节点,表长度为N,节点的数据值为1---N
Node* init(int N)
{
	Node * head=NULL;
	Node *q=NULL;
	for (int i=1;i<=N;i++)
	{
		if (i==1)
		{
			Node *p=(Node *)malloc(sizeof(Node));
			p->data=i;
			p->flag=false;
			head=p;
			q=p;
			q->next=head;
		
		}
		else
		{
			Node *p=(Node *)malloc(sizeof(Node));
			p->data=i;p->flag=false;
			q->next=p;
			q=p;
			q->next=head;	
		}
	}
	return head;
}
//打印所建立的循环链表,测试建表成功
void printLink(Node *head)
{
	Node *p=head;
	
	do{
		cout<<p->data<<", ";
		p=p->next;
	}while (p!=head);
	cout<<endl;
}
//判断是否还有没有打印出来的节点
int isallflag(Node * head)
{
	Node *p=head;
	int k=0;
	do{
		if (p->flag==false)
		{
			k=1;
		}
		p=p->next;
		
	}while (p!=head);
	return k;
}
//功能函数,约瑟夫环,打印出一个标记一个点,直至都打印出来
void fun(Node * head,int m)
{
	Node *p=head;
   int ct=1;
   while (isallflag(head)==1)
   {
	  
	
	   if (ct==m)
	   {
		   if (p->flag==false)
		   {
			    p->flag=true;
		        cout<<p->data<<endl;
			
		   }
		  	ct=1;
		    p=p->next;
		   
	   }
	   else
	   {
		   ct++;
		   p=p->next;
	   }
   }
}
int main(void)  
{  
	int m=0,n=0;
	cout<<"input m,n\n";
	cin>>m;
	cin>>n;
	Node *head=init(n);
	fun(head,m);
    return 0;  
}  



14.不能做switch()的参数类型是:

     switch的参数不能为实型。只能是整型和字符型

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值