惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

S
SegmentFault 最新的问题
爱范儿
爱范儿
博客园 - 三生石上(FineUI控件)
Microsoft Security Blog
Microsoft Security Blog
Google DeepMind News
Google DeepMind News
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
GbyAI
GbyAI
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
V
V2EX
酷 壳 – CoolShell
酷 壳 – CoolShell
量子位
博客园_首页
T
Tailwind CSS Blog
aimingoo的专栏
aimingoo的专栏
A
About on SuperTechFans
T
The Blog of Author Tim Ferriss
Stack Overflow Blog
Stack Overflow Blog
Recent Announcements
Recent Announcements
P
Proofpoint News Feed
博客园 - 司徒正美
有赞技术团队
有赞技术团队
Engineering at Meta
Engineering at Meta
Last Week in AI
Last Week in AI
MongoDB | Blog
MongoDB | Blog

博客园 - Nillson

传说中的Singleton.... 设计模式--简单工厂模式 策略模式 抽象类与接口 C# 实现的一个二叉树类 再谈代理 常见的排序方法 预定义,宏定义 连接符,数值运算与函数 复杂查询 数据库中的Index和View的理解 重载和重写 采用递归的方法获得一棵树的所有叶节点 .NET中的新概念整理 4月要看的书 System.Runtime.InteropServices浅见 挂个牛人 一篇关于如何写注释的文章,值得收藏 Vistual Studio 2005到Vistual Studio 2008的版本转换问题 Visual Studio 2008 的一个Bug
回顾一个面试题
Nillson · 2008-07-11 · via 博客园 - Nillson

关于算法面试了两个题目:第一个是判断两个平面内的矩形是否可能发生碰撞;第二个是要写出逐层遍历二叉树的算法。个人感觉都不是很难,下面给出我的思路和解法。

设计一个数据结构来表示矩形,并用该结构作为参数来实现判断两个巨型是否发生碰撞的函数。

struct Rectangle
    {
        public Point leftUp;
        public Point rightDown;
    }
    class HitCheck
    {
        private Rectangle rectA = new Rectangle();
        private Rectangle rectB = new Rectangle();
        public HitCheck(Rectangle recA, Rectangle recB)
        {
            rectA = recA;
            rectB = recB;
        }
        public bool IsHited()
        {
            if (rectA.leftUp.X > rectB.rightDown.X || rectA.rightDown.X < rectB.leftUp.X || rectA.leftUp.Y > rectB.rightDown.Y || rectA.rightDown.Y < rectB.leftUp.Y)//如果左矩形的右边框在右矩形左边,左边框在右矩形右边,上边框在右矩形下边,下边框在右矩形上边则不相交,反之相交。
            {
                return false;
            }
            else if (rectB.leftUp.X > rectA.rightDown.X || rectB.rightDown.X < rectA.leftUp.X || rectB.leftUp.Y > rectA.rightDown.Y || rectB.rightDown.Y < rectA.leftUp.Y)
            {
                return false;
            }
            return true;
        }
    }

设计一个算法来“逐层”遍历二叉树。