一、简答题:
二、程序设计题:
三、系统设计题
略
简述OSI七层模型
Linux中进程间通信的方式(至少三种)
二、程序设计题:
1、整型数组int[] arrays={a_0,a_1,a_2,...a_n};输出其中数字的所有组合
#include<stdio.h>
#include<stdlib.h>
void visit(int arrays[], int length)
{
int i;
printf("\n");
for(i=0;i<length;i++)
{
printf("%d\t",arrays[i]);
}
printf("\n");
}
void swap(int arrays[], int i, int j)
{
arrays[i]=arrays[i]^arrays[j];
arrays[j]=arrays[i]^arrays[j];
arrays[i]=arrays[i]^arrays[j];
}
void visit(int arrays[], int start, int length)
{
if(start==length)
{
visit(arrays, length);
return ;
}
visit(arrays, start+1, length);
for(int i=start+1; i<length;i++)
{
swap(arrays, i, start);
visit(arrays, start+1, length);
swap(arrays, i, start);
}
}
void rank(int arrays[], int length)
{
visit(arrays, 0, length);
}
int main()
{
int arrays[]={1,2,3};
rank(arrays, 3);
return 0;
}
2、有这样一个数组A,大小为n,相邻元素差的绝对值都是1。如:A={4,5,6,5,6,7,8,9,10,9}。 现在,给定A和目标整数t,请找到t在A中的位置。
#include<stdio.h>
#include<stdlib.h>
void find(int arrays[], int num, int length)
{
int i=0,find=0;
while(i<length)
{
int minus=arrays[i]-num;
if(minus==0)
{
find=1;
printf("location:\t %d\n",i);
i++;
}
else
{
if(minus<0)
minus*=-1;
i+=minus;
}
}
if(!find)
{
printf("\nNo data!\n");
}
}
int main()
{
int arrays[]={4,5,6,5,6,7,8,9,10,9};
printf("input number:\n");
int num;
scanf("%d",&num);
find(arrays, num, 10);
return 0;
}
3、给定一棵二叉树,二叉树的高度定义为二叉树的层数,二叉树的宽度定义为二叉树各层中节点个数的最大值,求二叉树的面积。
#include<stdlib.h>
#include<stdio.h>
typedef struct BNode
{
BNode* lchild;
BNode* rchild;
int value;
}*BTree;
BNode* initNode(int value)
{
BNode* node=(BNode*)malloc(sizeof(BNode));
node->lchild=NULL;
node->rchild=NULL;
node->value=value;
return node;
}
BNode* initNode()
{
return initNode(0);
}
BTree createBTree()
{
BTree root=initNode();
root->lchild=initNode(1);
root->rchild=initNode(2);
root->lchild->lchild=initNode(3);
root->lchild->rchild=initNode(4);
root->rchild->lchild=initNode(5);
root->rchild->rchild=initNode(6);
return root;
}
int height(BTree root)
{
if(root->lchild!=NULL&&root->rchild!=NULL)
{
int h1=height(root->lchild)+1;
int h2=height(root->rchild)+1;
return h1>h2?h1:h2;
}
else if(root->lchild!=NULL)
return height(root->lchild)+1;
else if(root->rchild!=NULL)
return height(root->rchild)+1;
else
return 1;
}
void width(BTree root, int n[], int i, int* max)
{
if(root)
{
i++;
if(root->lchild) n[i]++;
if(root->rchild) n[i]++;
if(*max<n[i]) *max=n[i];
width(root->lchild, n, i, max);
width(root->rchild, n, i, max);
}
}
int width(BTree root)
{
int n[20]={0};
int i=0;
int max=0;
if(root)
{
n[i]++;
max=n[i];
i++;
if(root->lchild) n[i]++;
if(root->rchild) n[i]++;
if(max<n[i]) max=n[i];
width(root->lchild, n, i, &max);
width(root->rchild, n, i, &max);
}
return max;
}
int main()
{
BTree root=createBTree();
int h=height(root);
int w=width(root);
int squre=w*h;
printf("squre is :%d\nwidth=%d\theight=%d\n",squre, w, h);
return 0;
}
三、系统设计题
略