## Stay hungry, stay foolish !

I've failed over and over and over again in my life. And that is why I succeed.

# 算法导论学习2.1-4 二进制加法

public class Binary_Plus {
public static void main(String[] args)
{
int[] a = {0,1,0};
int[] b = {0,1,0};
int[] c = new int[a.length + 1];
plus(a,b,c);
for(int i = 0; i < c.length; i ++)
{
System.out.print(c[i] + " ");
}

}

static void plus(int[] a, int[] b, int[] c)
{
int ia, ib, k = 0;
ia = a.length - 1;
ib = b.length - 1;
for(; ia >= 0; ia--,ib--)
{
k = a[ia] + b[ib] + k;
//			if(k==2)
//			{
//				c[ia + 1] = 0;
//				k = 1;
//			}
//			else if(k ==3)
//			{
//				c[ia + 1] = 1;
//				k = 1;
//			}
//			else if(k == 1)
//			{
//				c[ia + 1] = k;
//				k = 0;
//			}
//			else
//			{
//				c[ia + 1] = k;
//			}

switch(k)
{
case 1 :
c[ia + 1] = k; k = 0; break;
case 2 :
c[ia + 1] = 0; k = 1; break;
case 3 :
c[ia + 1] = 1; k = 1; break;
default :
c[ia + 1] = k;
}
}
c[ia + 1] = k;
}
}


06-25 4382

06-29 271

10-27 443

12-13 1111

03-15 471

11-15 201

03-15 273

07-16 276

09-24 558

04-17 143